src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ContinuousArrayData.java
author hannesw
Wed, 21 Mar 2018 16:55:34 +0100
changeset 49275 c639a6b33c5c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199869: Missing copyright headers in nashorn source code Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     1
/*
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     3
 *
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
     9
 *
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    14
 * accompanied this code).
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    15
 *
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    19
 *
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    22
 * questions.
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    23
 */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    24
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    25
package jdk.nashorn.internal.runtime.arrays;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    26
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    27
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    28
import static jdk.nashorn.internal.lookup.Lookup.MH;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    29
import static jdk.nashorn.internal.runtime.JSType.getAccessorTypeIndex;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    30
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    31
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    32
import java.lang.invoke.MethodHandle;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    33
import java.lang.invoke.MethodHandles;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    34
import java.lang.invoke.MethodType;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    35
import java.lang.invoke.SwitchPoint;
34447
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 32534
diff changeset
    36
import jdk.dynalink.CallSiteDescriptor;
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 32534
diff changeset
    37
import jdk.dynalink.linker.GuardedInvocation;
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 32534
diff changeset
    38
import jdk.dynalink.linker.LinkRequest;
27104
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26886
diff changeset
    39
import jdk.nashorn.internal.codegen.types.Type;
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    40
import jdk.nashorn.internal.lookup.Lookup;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    41
import jdk.nashorn.internal.runtime.ScriptObject;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    42
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    43
import jdk.nashorn.internal.runtime.logging.Logger;
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    44
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    45
/**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    46
 * Interface implemented by all arrays that are directly accessible as underlying
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    47
 * native arrays
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    48
 */
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    49
@Logger(name="arrays")
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
    50
public abstract class ContinuousArrayData extends ArrayData {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    51
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    52
     * Constructor
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    53
     * @param length length (elementLength)
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    54
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    55
    protected ContinuousArrayData(final long length) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    56
        super(length);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    57
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    58
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    59
    /**
28787
cab4b0497d27 8068872: Nashorn JSON.parse drops numeric keys
hannesw
parents: 27525
diff changeset
    60
     * Check if we can put one more element at the end of this continuous
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    61
     * array without reallocating, or if we are overwriting an already
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    62
     * allocated element
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    63
     *
26886
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
    64
     * @param index index to check
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    65
     * @return true if we don't need to do any array reallocation to fit an element at index
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    66
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    67
    public final boolean hasRoomFor(final int index) {
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27209
diff changeset
    68
        return has(index) || (index == length() && ensure(index) == this);
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    69
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    70
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    71
    /**
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: 27104
diff changeset
    72
     * Check if an arraydata is 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: 27104
diff changeset
    73
     * @return true if 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: 27104
diff changeset
    74
     */
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: 27104
diff changeset
    75
    public boolean isEmpty() {
27525
e7d3c00b9fb8 8035312: Various array and ScriptObject length issues for non writable length fields
lagergren
parents: 27209
diff changeset
    76
        return length() == 0L;
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: 27104
diff changeset
    77
    }
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: 27104
diff changeset
    78
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: 27104
diff changeset
    79
    /**
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    80
     * Return element getter for a certain type at a certain program point
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    81
     * @param returnType   return type
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    82
     * @param programPoint program point
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    83
     * @return element getter or null if not supported (used to implement slow linkage instead
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    84
     *   as fast isn't possible)
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    85
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    86
    public abstract MethodHandle getElementGetter(final Class<?> returnType, final int programPoint);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    87
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    88
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    89
     * Return element getter for a certain type at a certain program point
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    90
     * @param elementType element type
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    91
     * @return element setter or null if not supported (used to implement slow linkage instead
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    92
     *   as fast isn't possible)
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    93
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    94
    public abstract MethodHandle getElementSetter(final Class<?> elementType);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    95
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    96
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    97
     * Version of has that throws a class cast exception if element does not exist
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    98
     * used for relinking
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
    99
     *
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   100
     * @param index index to check - currently only int indexes
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   101
     * @return index
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   102
     */
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: 27104
diff changeset
   103
    protected final int throwHas(final int index) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   104
        if (!has(index)) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   105
            throw new ClassCastException();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   106
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   107
        return index;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   108
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   109
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: 27104
diff changeset
   110
    @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: 27104
diff changeset
   111
    public abstract ContinuousArrayData 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: 27104
diff changeset
   112
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   113
    /**
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   114
     * Returns the type used to store an element in this array
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   115
     * @return element type
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   116
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   117
    public abstract Class<?> getElementType();
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   118
27104
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26886
diff changeset
   119
    @Override
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26886
diff changeset
   120
    public Type getOptimisticType() {
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26886
diff changeset
   121
        return Type.typeFor(getElementType());
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26886
diff changeset
   122
    }
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26886
diff changeset
   123
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   124
    /**
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: 27104
diff changeset
   125
     * Returns the boxed type of the type used to store an element in this 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: 27104
diff changeset
   126
     * @return element type
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: 27104
diff changeset
   127
     */
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: 27104
diff changeset
   128
    public abstract 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: 27104
diff changeset
   129
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: 27104
diff changeset
   130
    /**
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: 27104
diff changeset
   131
     * Get the widest element type of two arrays. This can be done faster in subclasses, but
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: 27104
diff changeset
   132
     * this works for all ContinuousArrayDatas and for where more optimal checks haven't been
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: 27104
diff changeset
   133
     * implemented.
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: 27104
diff changeset
   134
     *
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: 27104
diff changeset
   135
     * @param otherData another 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: 27104
diff changeset
   136
     * @return the widest boxed element type
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: 27104
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: 27104
diff changeset
   138
    public ContinuousArrayData widest(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: 27104
diff changeset
   139
        final Class<?> elementType = 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: 27104
diff changeset
   140
        return Type.widest(elementType, otherData.getElementType()) == elementType ? this : 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: 27104
diff changeset
   141
    }
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: 27104
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: 27104
diff changeset
   143
    /**
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   144
     * Look up a continuous array element getter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   145
     * @param get          getter, sometimes combined with a has check that throws CCE on failure for relink
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   146
     * @param returnType   return type
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   147
     * @param programPoint program point
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   148
     * @return array getter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   149
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   150
    protected final MethodHandle getContinuousElementGetter(final MethodHandle get, final Class<?> returnType, final int programPoint) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   151
        return getContinuousElementGetter(getClass(), get, returnType, programPoint);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   152
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   153
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   154
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   155
     * Look up a continuous array element setter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   156
     * @param set          setter, sometimes combined with a has check that throws CCE on failure for relink
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   157
     * @param returnType   return type
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   158
     * @return array setter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   159
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   160
    protected final MethodHandle getContinuousElementSetter(final MethodHandle set, final Class<?> returnType) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   161
        return getContinuousElementSetter(getClass(), set, returnType);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   162
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   163
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   164
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   165
     * Return element getter for a {@link ContinuousArrayData}
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   166
     * @param clazz        clazz for exact type guard
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   167
     * @param getHas       has getter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   168
     * @param returnType   return type
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   169
     * @param programPoint program point
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   170
     * @return method handle for element setter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   171
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   172
    protected MethodHandle getContinuousElementGetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle getHas, final Class<?> returnType, final int programPoint) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   173
        final boolean isOptimistic = isValid(programPoint);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   174
        final int     fti          = getAccessorTypeIndex(getHas.type().returnType());
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   175
        final int     ti           = getAccessorTypeIndex(returnType);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   176
        MethodHandle  mh           = getHas;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   177
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   178
        if (isOptimistic) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   179
            if (ti < fti) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   180
                mh = MH.insertArguments(ArrayData.THROW_UNWARRANTED.methodHandle(), 1, programPoint);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   181
            }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   182
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   183
        mh = MH.asType(mh, mh.type().changeReturnType(returnType).changeParameterType(0, clazz));
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   184
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   185
        if (!isOptimistic) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   186
            //for example a & array[17];
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   187
            return Lookup.filterReturnType(mh, returnType);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   188
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   189
        return mh;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   190
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   191
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   192
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   193
     * Return element setter for a {@link ContinuousArrayData}
32534
b3ec7f3b3c2a 8136349: Typos patch for nashorn sources submitted on Sep 10, 2015
sundar
parents: 31549
diff changeset
   194
     * @param clazz        class for exact type guard
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   195
     * @param setHas       set has guard
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   196
     * @param elementType  element type
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   197
     * @return method handle for element setter
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   198
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   199
    protected MethodHandle getContinuousElementSetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle setHas, final Class<?> elementType) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   200
        return MH.asType(setHas, setHas.type().changeParameterType(2, elementType).changeParameterType(0, clazz));
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   201
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   202
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   203
    /** Fast access guard - it is impractical for JIT performance reasons to use only CCE asType as guard :-(, also we need
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   204
      the null case explicitly, which is the one that CCE doesn't handle */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   205
    protected static final MethodHandle FAST_ACCESS_GUARD =
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   206
            MH.dropArguments(
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   207
                    staticCall(
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   208
                            MethodHandles.lookup(),
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   209
                            ContinuousArrayData.class,
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   210
                            "guard",
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   211
                            boolean.class,
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   212
                            Class.class,
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   213
                            ScriptObject.class).methodHandle(),
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   214
                    2,
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   215
                    int.class);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   216
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   217
    @SuppressWarnings("unused")
31549
b627094c5649 8130734: Apply transformations found by netbeans Refactor->Inspect and transform menu
sundar
parents: 28787
diff changeset
   218
    private static boolean guard(final Class<? extends ContinuousArrayData> clazz, final ScriptObject sobj) {
b627094c5649 8130734: Apply transformations found by netbeans Refactor->Inspect and transform menu
sundar
parents: 28787
diff changeset
   219
        return sobj != null && sobj.getArray().getClass() == clazz;
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   220
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   221
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   222
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   223
     * Return a fast linked array getter, or null if we have to dispatch to super class
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   224
     * @param desc     descriptor
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   225
     * @param request  link request
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   226
     * @return invocation or null if needs to be sent to slow relink
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   227
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   228
    @Override
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   229
    public GuardedInvocation findFastGetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   230
        final MethodType callType   = desc.getMethodType();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   231
        final Class<?>   indexType  = callType.parameterType(1);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   232
        final Class<?>   returnType = callType.returnType();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   233
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   234
        if (ContinuousArrayData.class.isAssignableFrom(clazz) && indexType == int.class) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   235
            final Object[] args  = request.getArguments();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   236
            final int      index = (int)args[args.length - 1];
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   237
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   238
            if (has(index)) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   239
                final MethodHandle getArray     = ScriptObject.GET_ARRAY.methodHandle();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   240
                final int          programPoint = NashornCallSiteDescriptor.isOptimistic(desc) ? NashornCallSiteDescriptor.getProgramPoint(desc) : INVALID_PROGRAM_POINT;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   241
                MethodHandle       getElement   = getElementGetter(returnType, programPoint);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   242
                if (getElement != null) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   243
                    getElement = MH.filterArguments(getElement, 0, MH.asType(getArray, getArray.type().changeReturnType(clazz)));
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   244
                    final MethodHandle guard = MH.insertArguments(FAST_ACCESS_GUARD, 0, clazz);
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24720
diff changeset
   245
                    return new GuardedInvocation(getElement, guard, (SwitchPoint)null, ClassCastException.class);
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   246
                }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   247
            }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   248
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   249
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   250
        return null;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   251
    }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   252
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   253
    /**
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   254
     * Return a fast linked array setter, or null if we have to dispatch to super class
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   255
     * @param desc     descriptor
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   256
     * @param request  link request
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   257
     * @return invocation or null if needs to be sent to slow relink
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   258
     */
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   259
    @Override
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   260
    public GuardedInvocation findFastSetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { // array, index, value
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   261
        final MethodType callType    = desc.getMethodType();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   262
        final Class<?>   indexType   = callType.parameterType(1);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   263
        final Class<?>   elementType = callType.parameterType(2);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   264
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   265
        if (ContinuousArrayData.class.isAssignableFrom(clazz) && indexType == int.class) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   266
            final Object[]        args  = request.getArguments();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   267
            final int             index = (int)args[args.length - 2];
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   268
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: 27104
diff changeset
   269
            if (hasRoomFor(index)) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   270
                MethodHandle setElement = getElementSetter(elementType); //Z(continuousarraydata, int, int), return true if successful
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   271
                if (setElement != null) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   272
                    //else we are dealing with a wider type than supported by this callsite
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   273
                    MethodHandle getArray = ScriptObject.GET_ARRAY.methodHandle();
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   274
                    getArray   = MH.asType(getArray, getArray.type().changeReturnType(getClass()));
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   275
                    setElement = MH.filterArguments(setElement, 0, getArray);
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   276
                    final MethodHandle guard = MH.insertArguments(FAST_ACCESS_GUARD, 0, clazz);
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: 27104
diff changeset
   277
                    return new GuardedInvocation(setElement, guard, (SwitchPoint)null, ClassCastException.class); //CCE if not a scriptObject anymore
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   278
                }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   279
            }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   280
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   281
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   282
        return null;
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   283
    }
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   284
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   285
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   286
     * Specialization - fast push implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   287
     * @param arg argument
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   288
     * @return new array length
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   289
     */
34974
94a13629c390 8143896: java.lang.Long is implicitly converted to double
hannesw
parents: 34447
diff changeset
   290
    public double fastPush(final int arg) {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   291
        throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   292
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   293
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   294
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   295
     * Specialization - fast push implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   296
     * @param arg argument
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   297
     * @return new array length
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   298
     */
34974
94a13629c390 8143896: java.lang.Long is implicitly converted to double
hannesw
parents: 34447
diff changeset
   299
    public double fastPush(final long arg) {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   300
        throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   301
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   302
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   303
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   304
     * Specialization - fast push implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   305
     * @param arg argument
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   306
     * @return new array length
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   307
     */
34974
94a13629c390 8143896: java.lang.Long is implicitly converted to double
hannesw
parents: 34447
diff changeset
   308
    public double fastPush(final double arg) {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   309
        throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   310
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   311
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   312
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   313
     * Specialization - fast push implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   314
     * @param arg argument
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   315
     * @return new array length
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   316
     */
34974
94a13629c390 8143896: java.lang.Long is implicitly converted to double
hannesw
parents: 34447
diff changeset
   317
    public double fastPush(final Object arg) {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   318
        throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   319
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   320
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   321
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   322
     * Specialization - fast pop implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   323
     * @return element value
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   324
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   325
    public int fastPopInt() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   326
        throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   327
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   328
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   329
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   330
     * Specialization - fast pop implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   331
     * @return element value
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   332
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   333
    public double fastPopDouble() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   334
       throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   335
    }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   336
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   337
    /**
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   338
     * Specialization - fast pop implementation
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   339
     * @return element value
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   340
     */
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   341
    public Object fastPopObject() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   342
        throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   343
    }
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: 27104
diff changeset
   344
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: 27104
diff changeset
   345
    /**
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: 27104
diff changeset
   346
     * Specialization - fast concat implementation
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: 27104
diff changeset
   347
     * @param otherData data to concat
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: 27104
diff changeset
   348
     * @return new arraydata
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: 27104
diff changeset
   349
     */
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: 27104
diff changeset
   350
    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: 27104
diff changeset
   351
        throw new ClassCastException(String.valueOf(getClass()) + " != " + String.valueOf(otherData.getClass()));
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: 27104
diff changeset
   352
    }
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents:
diff changeset
   353
}