src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42790 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java@edb30aa1a99b
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
35726
621225a25d50 8149334: JSON.parse(JSON.stringify([])).push(10) creates an array containing two elements
mhaupt
parents: 34732
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.runtime.arrays;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
    28
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
28576
37b0c5bda589 8067880: Dead typed push methods in ArrayData
attila
parents: 28126
diff changeset
    29
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
import java.lang.invoke.MethodHandle;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
    31
import java.lang.invoke.MethodHandles;
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    32
import java.lang.reflect.Array;
23078
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
    33
import java.nio.ByteBuffer;
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    34
import java.util.ArrayList;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    35
import java.util.Iterator;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    36
import java.util.List;
34447
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 33343
diff changeset
    37
import jdk.dynalink.CallSiteDescriptor;
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 33343
diff changeset
    38
import jdk.dynalink.linker.GuardedInvocation;
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 33343
diff changeset
    39
import jdk.dynalink.linker.LinkRequest;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
    40
import jdk.nashorn.internal.codegen.CompilerConstants;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
    41
import jdk.nashorn.internal.codegen.types.Type;
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23078
diff changeset
    42
import jdk.nashorn.internal.objects.Global;
19897
4235a28bb5e8 8024847: Java.to should accept mirror and external JSObjects as array-like objects as well
sundar
parents: 19236
diff changeset
    43
import jdk.nashorn.internal.runtime.JSType;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
import jdk.nashorn.internal.runtime.PropertyDescriptor;
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    45
import jdk.nashorn.internal.runtime.ScriptRuntime;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
    46
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
 * ArrayData - abstraction for wrapping array elements
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
public abstract class ArrayData {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
    /** Minimum chunk size for underlying arrays */
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
    53
    protected static final int CHUNK_SIZE = 32;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    55
    /** Untouched data - still link callsites as IntArrayData, but expands to
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    56
     *  a proper ArrayData when we try to write to it */
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    57
    public static final ArrayData EMPTY_ARRAY = new UntouchedArrayData();
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    58
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
    /**
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    60
     * Length of the array data. Not necessarily length of the wrapped array.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    61
     * This is private to ensure that no one in a subclass is able to touch the length
27817
56f6161c3e55 8057980: let & const: remaining issues with lexical scoping
hannesw
parents: 27525
diff changeset
    62
     * without going through {@link #setLength}. This is used to implement
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    63
     * {@link LengthNotWritableFilter}s, ensuring that there are no ways past
27817
56f6161c3e55 8057980: let & const: remaining issues with lexical scoping
hannesw
parents: 27525
diff changeset
    64
     * a {@link #setLength} function replaced by a nop
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    65
     */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    66
    private long length;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    67
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    68
    /**
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    69
     * Method handle to throw an {@link UnwarrantedOptimismException} when getting an element
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    70
     * of the wrong type
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    71
     */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    72
    protected static final CompilerConstants.Call THROW_UNWARRANTED = staticCall(MethodHandles.lookup(), ArrayData.class, "throwUnwarranted", void.class, ArrayData.class, int.class, int.class);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    73
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
    74
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
     * Immutable empty array to get ScriptObjects started.
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    76
     * Use the same array and convert it to mutable as soon as it is modified
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
     */
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    78
    private static class UntouchedArrayData extends ContinuousArrayData {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    79
        private UntouchedArrayData() {
27817
56f6161c3e55 8057980: let & const: remaining issues with lexical scoping
hannesw
parents: 27525
diff changeset
    80
            super(0);
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    81
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    82
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    83
        private ArrayData toRealArrayData() {
35726
621225a25d50 8149334: JSON.parse(JSON.stringify([])).push(10) creates an array containing two elements
mhaupt
parents: 34732
diff changeset
    84
            return new IntArrayData(0);
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    85
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    86
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    87
        private ArrayData toRealArrayData(final int index) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    88
            final IntArrayData newData = new IntArrayData(index + 1);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    89
            return new DeletedRangeArrayFilter(newData, 0, index);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    90
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    91
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    92
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    93
        public ContinuousArrayData copy() {
27817
56f6161c3e55 8057980: let & const: remaining issues with lexical scoping
hannesw
parents: 27525
diff changeset
    94
            assert length() == 0;
56f6161c3e55 8057980: let & const: remaining issues with lexical scoping
hannesw
parents: 27525
diff changeset
    95
            return this;
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    96
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    97
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    98
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
    99
        public Object asArrayOfType(final Class<?> componentType) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   100
            return Array.newInstance(componentType, 0);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   101
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   102
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   103
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   104
        public Object[] asObjectArray() {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   105
            return ScriptRuntime.EMPTY_ARRAY;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   106
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   107
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   108
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   109
        public ArrayData ensure(final long safeIndex) {
42790
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   110
            assert safeIndex >= 0L;
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   111
            if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) {
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   112
                return new SparseArrayData(this, safeIndex + 1);
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   113
            }
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   114
            //known to fit in int
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   115
            return toRealArrayData((int)safeIndex);
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   116
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   117
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   118
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   119
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   120
        public ArrayData convert(final Class<?> type) {
35726
621225a25d50 8149334: JSON.parse(JSON.stringify([])).push(10) creates an array containing two elements
mhaupt
parents: 34732
diff changeset
   121
            return toRealArrayData().convert(type);
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   122
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   123
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   124
        @Override
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   125
        public ArrayData delete(final int index) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   126
            return new DeletedRangeArrayFilter(this, index, index);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   127
        }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   128
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   129
        @Override
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   130
        public ArrayData delete(final long fromIndex, final long toIndex) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   131
            return new DeletedRangeArrayFilter(this, fromIndex, toIndex);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   132
        }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   133
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   134
        @Override
42790
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   135
        public ArrayData shiftLeft(final int by) {
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   136
            return this; //nop, always empty or we wouldn't be of this class
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   137
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   138
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   139
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   140
        public ArrayData shiftRight(final int by) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   141
            return this; //always empty or we wouldn't be of this class
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   142
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   143
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   144
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   145
        public ArrayData shrink(final long newLength) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   146
            return this;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   147
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   148
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   149
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   150
        public ArrayData set(final int index, final Object value, final boolean strict) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   151
            return toRealArrayData(index).set(index, value, strict);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   152
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   153
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   154
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   155
        public ArrayData set(final int index, final int value, final boolean strict) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   156
            return toRealArrayData(index).set(index, value, strict);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   157
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   158
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   159
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   160
        public ArrayData set(final int index, final double value, final boolean strict) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   161
            return toRealArrayData(index).set(index, value, strict);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   162
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   163
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   164
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   165
        public int getInt(final int index) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   166
            throw new ArrayIndexOutOfBoundsException(index); //empty
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   167
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   168
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   169
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   170
        public double getDouble(final int index) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   171
            throw new ArrayIndexOutOfBoundsException(index); //empty
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   172
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   173
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   174
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   175
        public Object getObject(final int index) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   176
            throw new ArrayIndexOutOfBoundsException(index); //empty
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   177
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   178
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   179
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   180
        public boolean has(final int index) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   181
            return false; //empty
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   182
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   183
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   184
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   185
        public Object pop() {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   186
            return ScriptRuntime.UNDEFINED;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   187
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   188
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   189
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   190
        public ArrayData push(final boolean strict, final Object item) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   191
            return toRealArrayData().push(strict, item);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   192
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   193
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   194
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   195
        public ArrayData slice(final long from, final long to) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   196
            return this; //empty
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   197
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   198
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   199
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   200
        public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   201
            return otherData.copy();
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   202
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   203
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   204
        //no need to override fastPopInt, as the default behavior is to throw classcast exception so we
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   205
        //can relink and return an undefined, this is the IntArrayData default behavior
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   206
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   207
        public String toString() {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   208
            return getClass().getSimpleName();
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   209
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   210
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   211
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   212
        public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   213
            return null;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   214
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   215
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   216
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   217
        public MethodHandle getElementSetter(final Class<?> elementType) {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   218
            return null;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   219
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   220
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   221
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   222
        public Class<?> getElementType() {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   223
            return int.class;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   224
        }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   225
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   226
        @Override
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   227
        public Class<?> getBoxedElementType() {
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   228
            return Integer.class;
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   229
        }
27817
56f6161c3e55 8057980: let & const: remaining issues with lexical scoping
hannesw
parents: 27525
diff changeset
   230
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   231
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   233
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   234
     * @param length Virtual length of the array.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   235
     */
19236
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   236
    protected ArrayData(final long length) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
        this.length = length;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   238
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   239
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   240
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
     * Factory method for unspecified array - start as int
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   242
     * @return ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   243
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   244
    public static ArrayData initialArray() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   245
        return new IntArrayData();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   246
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   247
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   248
    /**
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   249
     * Unwarranted thrower
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   250
     *
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   251
     * @param data         array data
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   252
     * @param programPoint program point
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   253
     * @param index        array index
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   254
     */
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   255
    protected static void throwUnwarranted(final ArrayData data, final int programPoint, final int index) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   256
        throw new UnwarrantedOptimismException(data.getObject(index), programPoint);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   257
    }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   258
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   259
    /**
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   260
     * Align an array size up to the nearest array chunk size
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   261
     * @param size size required
28126
9e60ca1ed968 8067636: ant javadoc target is broken
sundar
parents: 27817
diff changeset
   262
     * @return size given, always &gt;= size
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   263
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   264
    protected static int alignUp(final int size) {
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   265
        return size + CHUNK_SIZE - 1 & ~(CHUNK_SIZE - 1);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   266
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   267
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   268
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   269
     * Factory method for unspecified array with given length - start as int array data
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   270
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   271
     * @param length the initial length
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   272
     * @return ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   273
     */
34732
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 34447
diff changeset
   274
    public static ArrayData allocate(final long length) {
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 34447
diff changeset
   275
        if (length == 0L) {
18881
3198876c1f4f 8020358: Array(0xfffffff) throws OutOfMemoryError
hannesw
parents: 18606
diff changeset
   276
            return new IntArrayData();
3198876c1f4f 8020358: Array(0xfffffff) throws OutOfMemoryError
hannesw
parents: 18606
diff changeset
   277
        } else if (length >= SparseArrayData.MAX_DENSE_LENGTH) {
3198876c1f4f 8020358: Array(0xfffffff) throws OutOfMemoryError
hannesw
parents: 18606
diff changeset
   278
            return new SparseArrayData(EMPTY_ARRAY, length);
3198876c1f4f 8020358: Array(0xfffffff) throws OutOfMemoryError
hannesw
parents: 18606
diff changeset
   279
        } else {
34732
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 34447
diff changeset
   280
            return new DeletedRangeArrayFilter(new IntArrayData((int) length), 0, length - 1);
18881
3198876c1f4f 8020358: Array(0xfffffff) throws OutOfMemoryError
hannesw
parents: 18606
diff changeset
   281
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   282
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   283
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   284
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   285
     * Factory method for unspecified given an array object
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   286
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   287
     * @param  array the array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   288
     * @return ArrayData wrapping this array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   289
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   290
    public static ArrayData allocate(final Object array) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   291
        final Class<?> clazz = array.getClass();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   292
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   293
        if (clazz == int[].class) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   294
            return new IntArrayData((int[])array, ((int[])array).length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   295
        } else if (clazz == double[].class) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   296
            return new NumberArrayData((double[])array, ((double[])array).length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   297
        } else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   298
            return new ObjectArrayData((Object[])array, ((Object[])array).length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   299
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   300
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   301
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
     * Allocate an ArrayData wrapping a given array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   304
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   305
     * @param array the array to use for initial elements
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   306
     * @return the ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   307
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   308
    public static ArrayData allocate(final int[] array) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   309
         return new IntArrayData(array, array.length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   310
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   311
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   312
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   313
     * Allocate an ArrayData wrapping a given array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   314
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   315
     * @param array the array to use for initial elements
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   316
     * @return the ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   317
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   318
    public static ArrayData allocate(final double[] array) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   319
        return new NumberArrayData(array, array.length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   320
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   321
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   322
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   323
     * Allocate an ArrayData wrapping a given array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   324
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   325
     * @param array the array to use for initial elements
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   326
     * @return the ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   328
    public static ArrayData allocate(final Object[] array) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
        return new ObjectArrayData(array, array.length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   330
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   331
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   332
    /**
23078
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   333
     * Allocate an ArrayData wrapping a given nio ByteBuffer
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   334
     *
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   335
     * @param buf the nio ByteBuffer to wrap
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   336
     * @return the ArrayData
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   337
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   338
    public static ArrayData allocate(final ByteBuffer buf) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   339
        return new ByteBufferArrayData(buf);
23078
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   340
    }
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   341
06c03700f884 8011964: need indexed access to externally-managed ByteBuffer
sundar
parents: 21438
diff changeset
   342
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   343
     * Apply a freeze filter to an ArrayData.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   344
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   345
     * @param underlying  the underlying ArrayData to wrap in the freeze filter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   346
     * @return the frozen ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   347
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   348
    public static ArrayData freeze(final ArrayData underlying) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   349
        return new FrozenArrayFilter(underlying);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   350
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   351
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   352
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   353
     * Apply a seal filter to an ArrayData.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   354
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   355
     * @param underlying  the underlying ArrayData to wrap in the seal filter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   356
     * @return the sealed ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   357
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   358
    public static ArrayData seal(final ArrayData underlying) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   359
        return new SealedArrayFilter(underlying);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   360
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   361
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   362
    /**
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   363
     * Prevent this array from being extended
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   364
     *
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   365
     * @param  underlying the underlying ArrayData to wrap in the non extensible filter
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   366
     * @return new array data, filtered
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   367
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   368
    public static ArrayData preventExtension(final ArrayData underlying) {
27209
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   369
        return new NonExtensibleArrayFilter(underlying);
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   370
    }
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   371
30d8609b9561 8061391: concat as a builtin optimistic form, had to remove NoTypedArrayData and replace it, as we throw away a lot of optimistic link opportunities with NoTypedArrayData not being Continuous
lagergren
parents: 26886
diff changeset
   372
    /**
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   373
     * Prevent this array from having its length reset
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   374
     *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   375
     * @param underlying the underlying ArrayDAta to wrap in the non extensible filter
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   376
     * @return new array data, filtered
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   377
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   378
    public static ArrayData setIsLengthNotWritable(final ArrayData underlying) {
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   379
        return new LengthNotWritableFilter(underlying);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   380
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   381
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   382
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   383
     * Return the length of the array data. This may differ from the actual
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
     * length of the array this wraps as length may be set or gotten as any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   385
     * other JavaScript Property
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   386
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   387
     * Even though a JavaScript array length may be a long, we only store
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   388
     * int parts for the optimized array access. For long lengths there
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   389
     * are special cases anyway.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   390
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   391
     * TODO: represent arrays with "long" lengths as a special ArrayData
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   392
     * that basically maps to the ScriptObject directly for better abstraction
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   393
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   394
     * @return the length of the data
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   395
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   396
    public final long length() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   397
        return length;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   398
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   399
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   400
    /**
19236
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   401
     * Return a copy of the array that can be modified without affecting this instance.
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   402
     * It is safe to return themselves for immutable subclasses.
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   403
     *
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   404
     * @return a new array
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   405
     */
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   406
    public abstract ArrayData copy();
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   407
73d242d205f9 8020132: Big object literal with numerical keys exceeds method size
hannesw
parents: 18881
diff changeset
   408
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   409
     * Return a copy of the array data as an Object array.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   410
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   411
     * @return an Object array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   412
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   413
    public abstract Object[] asObjectArray();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   414
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   415
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   416
     * Return a copy of the array data as an array of the specified type.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   417
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   418
     * @param componentType  the type of elements in the array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   419
     * @return and array of the given type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   420
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   421
    public Object asArrayOfType(final Class<?> componentType) {
19897
4235a28bb5e8 8024847: Java.to should accept mirror and external JSObjects as array-like objects as well
sundar
parents: 19236
diff changeset
   422
        return JSType.convertArray(asObjectArray(), componentType);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   423
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   424
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   425
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   426
     * Set the length of the data array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   427
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   428
     * @param length the new length for the data array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   429
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   430
    public void setLength(final long length) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   431
        this.length = length;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   432
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   433
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   434
    /**
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   435
     * Increase length by 1
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   436
     * @return the new length, not the old one (i.e. pre-increment)
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   437
     */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   438
    protected final long increaseLength() {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   439
        return ++this.length;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   440
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   441
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   442
    /**
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   443
     * Decrease length by 1.
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   444
     * @return the new length, not the old one (i.e. pre-decrement)
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   445
     */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   446
    protected final long decreaseLength() {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   447
        return --this.length;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   448
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   449
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   450
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   451
     * Shift the array data left
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   452
     *
42790
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   453
     * TODO: This is used for Array.prototype.shift() which only shifts by 1,
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   454
     * so we might consider dropping the offset parameter.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   455
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   456
     * @param by offset to shift
42790
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   457
     * @return New arraydata (or same)
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   458
     */
42790
edb30aa1a99b 8171219: Missing checks in sparse array shift() implementation
hannesw
parents: 35726
diff changeset
   459
    public abstract ArrayData shiftLeft(final int by);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   460
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   461
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   462
     * Shift the array right
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   463
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   464
     * @param by offset to shift
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   465
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   466
     * @return New arraydata (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   467
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   468
    public abstract ArrayData shiftRight(final int by);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   469
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   470
    /**
28787
cab4b0497d27 8068872: Nashorn JSON.parse drops numeric keys
hannesw
parents: 28576
diff changeset
   471
     * Ensure that the given index exists and won't fail in a subsequent access.
cab4b0497d27 8068872: Nashorn JSON.parse drops numeric keys
hannesw
parents: 28576
diff changeset
   472
     * If {@code safeIndex} is equal or greater than the current length the length is
cab4b0497d27 8068872: Nashorn JSON.parse drops numeric keys
hannesw
parents: 28576
diff changeset
   473
     * updated to {@code safeIndex + 1}.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   474
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   475
     * @param safeIndex the index to ensure wont go out of bounds
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   476
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   477
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   478
    public abstract ArrayData ensure(final long safeIndex);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   479
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   480
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   481
     * Shrink the array to a new length, may or may not retain the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   482
     * inner array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   483
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   484
     * @param newLength new max length
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   485
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   486
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   487
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   488
    public abstract ArrayData shrink(final long newLength);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   489
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   490
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   491
     * Set an object value at a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   492
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   493
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   494
     * @param value the value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   495
     * @param strict are we in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   496
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   497
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   498
    public abstract ArrayData set(final int index, final Object value, final boolean strict);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   499
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   500
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   501
     * Set an int value at a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   502
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   503
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   504
     * @param value the value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   505
     * @param strict are we in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   506
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   507
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   508
    public abstract ArrayData set(final int index, final int value, final boolean strict);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   509
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   510
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   511
     * Set an double value at a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   512
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   513
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   514
     * @param value the value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   515
     * @param strict are we in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   516
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   517
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   518
    public abstract ArrayData set(final int index, final double value, final boolean strict);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   519
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   520
    /**
18606
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   521
     * Set an empty value at a given index. Should only affect Object array.
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   522
     *
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   523
     * @param index the index
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   524
     * @return new array data (or same)
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   525
     */
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   526
    public ArrayData setEmpty(final int index) {
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   527
        // Do nothing.
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   528
        return this;
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   529
    }
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   530
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   531
    /**
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   532
     * Set an empty value for a given range. Should only affect Object array.
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   533
     *
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   534
     * @param lo range low end
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   535
     * @param hi range high end
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   536
     * @return new array data (or same)
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   537
     */
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   538
    public ArrayData setEmpty(final long lo, final long hi) {
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   539
        // Do nothing.
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   540
        return this;
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   541
    }
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   542
5704d7a4a0a8 8010697: DeletedArrayFilter seems to leak memory
jlaskey
parents: 16151
diff changeset
   543
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   544
     * Get an int value from a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   545
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   546
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   547
     * @return the value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   548
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   549
    public abstract int getInt(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   550
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   551
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   552
     * Returns the optimistic type of this array data. Basically, when an array data object needs to throw an
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   553
     * {@link UnwarrantedOptimismException}, this type is used as the actual type of the return value.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   554
     * @return the optimistic type of this array data.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   555
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   556
    public Type getOptimisticType() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   557
        return Type.OBJECT;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   558
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   559
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   560
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   561
     * Get optimistic int - default is that it's impossible. Overridden
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   562
     * by arrays that actually represents ints
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   563
     *
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   564
     * @param index        the index
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   565
     * @param programPoint program point
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   566
     * @return the value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   567
     */
24741
4232289c3235 8040102: Remove all references to Unsafe and definition of anonymous clases from the code
lagergren
parents: 24727
diff changeset
   568
    public int getIntOptimistic(final int index, final int programPoint) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   569
        throw new UnwarrantedOptimismException(getObject(index), programPoint, getOptimisticType());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   570
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   571
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   572
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   573
     * Get a double value from a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   574
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   575
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   576
     * @return the value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   577
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   578
    public abstract double getDouble(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   579
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   580
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   581
     * Get optimistic double - default is that it's impossible. Overridden
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   582
     * by arrays that actually represents doubles or narrower
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   583
     *
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   584
     * @param index        the index
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   585
     * @param programPoint program point
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   586
     * @return the value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   587
     */
24741
4232289c3235 8040102: Remove all references to Unsafe and definition of anonymous clases from the code
lagergren
parents: 24727
diff changeset
   588
    public double getDoubleOptimistic(final int index, final int programPoint) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   589
        throw new UnwarrantedOptimismException(getObject(index), programPoint, getOptimisticType());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   590
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   591
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   592
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   593
     * Get an Object value from a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   594
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   595
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   596
     * @return the value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   597
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   598
    public abstract Object getObject(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   599
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   600
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   601
     * Tests to see if an entry exists (avoids boxing.)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   602
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   603
     * @return true if entry exists
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   604
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   605
    public abstract boolean has(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   606
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   607
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   608
     * Returns if element at specific index can be deleted or not.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   609
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   610
     * @param index the index of the element
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   611
     * @param strict are we in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   612
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   613
     * @return true if element can be deleted
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   614
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   615
    public boolean canDelete(final int index, final boolean strict) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   616
        return true;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   617
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   618
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   619
    /**
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   620
     * Returns if element at specific index can be deleted or not.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   621
     *
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   622
     * @param longIndex  the index
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   623
     * @param strict     are we in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   624
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   625
     * @return true if range can be deleted
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   626
     */
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   627
    public boolean canDelete(final long longIndex, final boolean strict) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   628
        return true;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   629
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   630
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   631
    /**
32892
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   632
     * Delete a range from the array if {@code fromIndex} is less than or equal to {@code toIndex}
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   633
     * and the array supports deletion.
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   634
     *
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   635
     * @param fromIndex  the start index (inclusive)
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   636
     * @param toIndex    the end index (inclusive)
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   637
     * @param strict     are we in strict mode
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   638
     * @return an array with the range deleted, or this array if no deletion took place
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   639
     */
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   640
    public final ArrayData safeDelete(final long fromIndex, final long toIndex, final boolean strict) {
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   641
        if (fromIndex <= toIndex && canDelete(fromIndex, strict)) {
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   642
            return delete(fromIndex, toIndex);
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   643
        }
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   644
        return this;
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   645
    }
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   646
7186b06a72cf 8138632: Sparse array does not handle growth of underlying dense array
hannesw
parents: 28787
diff changeset
   647
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   648
     * Returns property descriptor for element at a given index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   649
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   650
     * @param global the global object
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   651
     * @param index  the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   652
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   653
     * @return property descriptor for element
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   654
     */
23375
a1110f2cbe75 8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents: 23078
diff changeset
   655
    public PropertyDescriptor getDescriptor(final Global global, final int index) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   656
        return global.newDataDescriptor(getObject(index), true, true, true);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   657
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   658
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   659
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   660
     * Delete an array value at the given index, substituting
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   661
     * for an undefined
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   662
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   663
     * @param index the index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   664
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   665
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   666
    public abstract ArrayData delete(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   667
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   668
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   669
     * Delete a given range from this array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   670
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   671
     * @param fromIndex  from index (inclusive)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   672
     * @param toIndex    to index (inclusive)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   673
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   674
     * @return new ArrayData after deletion
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   675
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   676
    public abstract ArrayData delete(final long fromIndex, final long toIndex);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   677
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   678
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   679
     * Convert the ArrayData to one with a different element type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   680
     * Currently Arrays are not collapsed to narrower types, just to
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   681
     * wider ones. Attempting to narrow an array will assert
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   682
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   683
     * @param type new element type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   684
     * @return new array data
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   685
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   686
    public abstract ArrayData convert(final Class<?> type);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   687
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   688
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   689
     * Push an array of items to the end of the array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   690
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   691
     * @param strict are we in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   692
     * @param items  the items
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   693
     * @return new array data (or same)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   694
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   695
    public ArrayData push(final boolean strict, final Object... items) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   696
        if (items.length == 0) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   697
            return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   698
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   699
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   700
        final Class<?>  widest  = widestType(items);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   701
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   702
        ArrayData newData = convert(widest);
26886
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
   703
        long      pos     = newData.length;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   704
        for (final Object item : items) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   705
            newData = newData.ensure(pos); //avoid sparse array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   706
            newData.set((int)pos++, item, strict);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   707
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   708
        return newData;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   709
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   710
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   711
    /**
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   712
     * Push an array of items to the end of the array
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   713
     *
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   714
     * @param strict are we in strict mode
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   715
     * @param item   the item
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   716
     * @return new array data (or same)
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   717
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   718
    public ArrayData push(final boolean strict, final Object item) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   719
        return push(strict, new Object[] { item });
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   720
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   721
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   722
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   723
     * Pop an element from the end of the array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   724
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   725
     * @return the popped element
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   726
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   727
    public abstract Object pop();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   728
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   729
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   730
     * Slice out a section of the array and return that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   731
     * subsection as a new array data: [from, to)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   732
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   733
     * @param from start index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   734
     * @param to   end index + 1
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   735
     * @return new array data
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   736
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   737
    public abstract ArrayData slice(final long from, final long to);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   738
21438
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   739
    /**
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   740
     * Fast splice operation. This just modifies the array according to the number of
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   741
     * elements added and deleted but does not insert the added elements. Throws
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   742
     * {@code UnsupportedOperationException} if fast splice operation is not supported
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   743
     * for this class or arguments.
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   744
     *
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   745
     * @param start start index of splice operation
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   746
     * @param removed number of removed elements
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   747
     * @param added number of added elements
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   748
     * @throws UnsupportedOperationException if fast splice is not supported for the class or arguments.
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   749
     * @return new arraydata, but this never happens because we always throw an exception
21438
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   750
     */
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   751
    public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   752
        throw new UnsupportedOperationException();
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   753
    }
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   754
4292865c758b 8026701: Array.prototype.splice is slow on dense arrays
hannesw
parents: 19897
diff changeset
   755
    static Class<?> widestType(final Object... items) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   756
        assert items.length > 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   757
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   758
        Class<?> widest = Integer.class;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   759
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   760
        for (final Object item : items) {
26378
ca7093bd5fd1 8056129: AtomicInteger is treated as primitive number with optimistic compilation
attila
parents: 25865
diff changeset
   761
            if (item == null) {
ca7093bd5fd1 8056129: AtomicInteger is treated as primitive number with optimistic compilation
attila
parents: 25865
diff changeset
   762
                return Object.class;
ca7093bd5fd1 8056129: AtomicInteger is treated as primitive number with optimistic compilation
attila
parents: 25865
diff changeset
   763
            }
ca7093bd5fd1 8056129: AtomicInteger is treated as primitive number with optimistic compilation
attila
parents: 25865
diff changeset
   764
            final Class<?> itemClass = item.getClass();
34732
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 34447
diff changeset
   765
            if (itemClass == Double.class || itemClass == Float.class || itemClass == Long.class) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   766
                if (widest == Integer.class) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   767
                    widest = Double.class;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   768
                }
26378
ca7093bd5fd1 8056129: AtomicInteger is treated as primitive number with optimistic compilation
attila
parents: 25865
diff changeset
   769
            } else if (itemClass != Integer.class && itemClass != Short.class && itemClass != Byte.class) {
ca7093bd5fd1 8056129: AtomicInteger is treated as primitive number with optimistic compilation
attila
parents: 25865
diff changeset
   770
                return Object.class;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   771
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   772
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   773
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   774
        return widest;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   775
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   776
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   777
    /**
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   778
     * Return a list of keys in the array for the iterators
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   779
     * @return iterator key list
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   780
     */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   781
    protected List<Long> computeIteratorKeys() {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   782
        final List<Long> keys = new ArrayList<>();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   783
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   784
        final long len = length();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   785
        for (long i = 0L; i < len; i = nextIndex(i)) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   786
            if (has((int)i)) {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   787
                keys.add(i);
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   788
            }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   789
        }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   790
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   791
        return keys;
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   792
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   793
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   794
    /**
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   795
     * Return an iterator that goes through all indexes of elements
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   796
     * in this array. This includes those after array.length if
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   797
     * they exist
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   798
     *
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   799
     * @return iterator
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   800
     */
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   801
    public Iterator<Long> indexIterator() {
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   802
        return computeIteratorKeys().iterator();
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   803
    }
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   804
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   805
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   806
     * Exponential growth function for array size when in
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   807
     * need of resizing.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   808
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   809
     * @param size current size
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   810
     * @return next size to allocate for internal array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   811
     */
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   812
    public static int nextSize(final int size) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   813
        return alignUp(size + 1) * 2;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   814
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   815
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   816
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   817
     * Return the next valid index from a given one. Subclassed for various
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   818
     * array representation
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   819
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   820
     * @param index the current index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   821
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   822
     * @return the next index
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   823
     */
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27364
diff changeset
   824
    long nextIndex(final long index) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   825
        return index + 1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   826
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   827
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   828
    static Object invoke(final MethodHandle mh, final Object arg) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   829
        try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   830
            return mh.invoke(arg);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   831
        } catch (final RuntimeException | Error e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   832
            throw e;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   833
        } catch (final Throwable t) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   834
            throw new RuntimeException(t);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   835
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   836
    }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 23078
diff changeset
   837
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   838
   /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   839
     * Find a fast call if one exists
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   840
     *
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   841
     * @param clazz    array data class
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   842
     * @param desc     callsite descriptor
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   843
     * @param request  link request
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   844
     * @return fast property getter if one is found
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   845
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   846
    public GuardedInvocation findFastCallMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   847
        return null;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   848
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26378
diff changeset
   849
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   850
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   851
     * Find a fast element getter if one exists
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   852
     *
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   853
     * @param clazz   array data class
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   854
     * @param desc    callsite descriptor
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   855
     * @param request link request
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   856
     * @return fast index getter if one is found
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   857
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   858
    public GuardedInvocation findFastGetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { // array, index, value
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   859
        return null;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   860
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   861
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   862
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   863
     * Find a fast element setter if one exists
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   864
     *
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   865
     * @param clazz   array data class
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   866
     * @param desc    callsite descriptor
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   867
     * @param request link request
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   868
     * @return fast index getter if one is found
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   869
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   870
    public GuardedInvocation findFastSetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { // array, index, value
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   871
        return null;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   872
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   873
}