src/jdk/nashorn/internal/runtime/arrays/ArrayFilter.java

Thu, 25 Sep 2014 15:53:47 +0200

author
lagergren
date
Thu, 25 Sep 2014 15:53:47 +0200
changeset 1028
d79265f2fa92
parent 963
e2497b11a021
child 1095
3dbb4c9ff43c
permissions
-rw-r--r--

8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
Reviewed-by: hannesw, attila, sundar

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jlaskey@3 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation. Oracle designates this
jlaskey@3 8 * particular file as subject to the "Classpath" exception as provided
jlaskey@3 9 * by Oracle in the LICENSE file that accompanied this code.
jlaskey@3 10 *
jlaskey@3 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 14 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 15 * accompanied this code).
jlaskey@3 16 *
jlaskey@3 17 * You should have received a copy of the GNU General Public License version
jlaskey@3 18 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jlaskey@3 20 *
jlaskey@3 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 22 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 23 * questions.
jlaskey@3 24 */
jlaskey@3 25
jlaskey@3 26 package jdk.nashorn.internal.runtime.arrays;
jlaskey@3 27
attila@963 28 import jdk.nashorn.internal.codegen.types.Type;
jlaskey@3 29 import jdk.nashorn.internal.runtime.ScriptRuntime;
jlaskey@3 30 import jdk.nashorn.internal.runtime.Undefined;
jlaskey@3 31 import jdk.nashorn.internal.runtime.linker.Bootstrap;
jlaskey@3 32
jlaskey@3 33 /**
jlaskey@3 34 * Base class for array filters. Implements all core routines so that the
jlaskey@3 35 * filter only has to implement those needed.
jlaskey@3 36 */
jlaskey@3 37 abstract class ArrayFilter extends ArrayData {
jlaskey@3 38 /** Underlying array. */
jlaskey@3 39 protected ArrayData underlying;
jlaskey@3 40
jlaskey@3 41 ArrayFilter(final ArrayData underlying) {
lagergren@1028 42 super(underlying.length);
jlaskey@3 43 this.underlying = underlying;
jlaskey@3 44 }
jlaskey@3 45
jlaskey@3 46 /**
jlaskey@3 47 * Get the underlying {@link ArrayData} that this filter wraps
jlaskey@3 48 * @return array data
jlaskey@3 49 */
jlaskey@3 50 protected ArrayData getUnderlying() {
jlaskey@3 51 return underlying;
jlaskey@3 52 }
jlaskey@3 53
jlaskey@3 54 @Override
jlaskey@3 55 public void setLength(final long length) {
jlaskey@3 56 super.setLength(length);
jlaskey@3 57 underlying.setLength(length);
jlaskey@3 58 }
jlaskey@3 59
jlaskey@3 60 @Override
jlaskey@3 61 public Object[] asObjectArray() {
jlaskey@3 62 return underlying.asObjectArray();
jlaskey@3 63 }
jlaskey@3 64
jlaskey@3 65 @Override
jlaskey@3 66 public Object asArrayOfType(final Class<?> componentType) {
jlaskey@3 67 return underlying.asArrayOfType(componentType);
jlaskey@3 68 }
jlaskey@3 69
jlaskey@3 70 @Override
jlaskey@3 71 public void shiftLeft(final int by) {
jlaskey@3 72 underlying.shiftLeft(by);
lagergren@1028 73 setLength(underlying.length);
jlaskey@3 74 }
jlaskey@3 75
jlaskey@3 76 @Override
jlaskey@3 77 public ArrayData shiftRight(final int by) {
jlaskey@3 78 underlying = underlying.shiftRight(by);
lagergren@1028 79 setLength(underlying.length);
jlaskey@3 80
jlaskey@3 81 return this;
jlaskey@3 82 }
jlaskey@3 83
jlaskey@3 84 @Override
jlaskey@3 85 public ArrayData ensure(final long safeIndex) {
jlaskey@3 86 underlying = underlying.ensure(safeIndex);
lagergren@1028 87 setLength(underlying.length);
jlaskey@3 88
jlaskey@3 89 return this;
jlaskey@3 90 }
jlaskey@3 91
jlaskey@3 92 @Override
jlaskey@3 93 public ArrayData shrink(final long newLength) {
jlaskey@3 94 underlying = underlying.shrink(newLength);
lagergren@1028 95 setLength(underlying.length);
jlaskey@3 96
jlaskey@3 97 return this;
jlaskey@3 98 }
jlaskey@3 99
jlaskey@3 100 @Override
jlaskey@3 101 public ArrayData set(final int index, final Object value, final boolean strict) {
jlaskey@3 102 underlying = underlying.set(index, value, strict);
lagergren@1028 103 setLength(underlying.length);
jlaskey@3 104
jlaskey@3 105 return this;
jlaskey@3 106 }
jlaskey@3 107
jlaskey@3 108 @Override
jlaskey@3 109 public ArrayData set(final int index, final int value, final boolean strict) {
jlaskey@3 110 underlying = underlying.set(index, value, strict);
lagergren@1028 111 setLength(underlying.length);
jlaskey@3 112
jlaskey@3 113 return this;
jlaskey@3 114 }
jlaskey@3 115
jlaskey@3 116 @Override
jlaskey@3 117 public ArrayData set(final int index, final long value, final boolean strict) {
jlaskey@3 118 underlying = underlying.set(index, value, strict);
lagergren@1028 119 setLength(underlying.length);
jlaskey@3 120
jlaskey@3 121 return this;
jlaskey@3 122 }
jlaskey@3 123
jlaskey@3 124 @Override
jlaskey@3 125 public ArrayData set(final int index, final double value, final boolean strict) {
jlaskey@3 126 underlying = underlying.set(index, value, strict);
lagergren@1028 127 setLength(underlying.length);
jlaskey@3 128
jlaskey@3 129 return this;
jlaskey@3 130 }
jlaskey@3 131
jlaskey@3 132 @Override
jlaskey@368 133 public ArrayData setEmpty(final int index) {
jlaskey@368 134 underlying.setEmpty(index);
jlaskey@368 135 return this;
jlaskey@368 136 }
jlaskey@368 137
jlaskey@368 138 @Override
jlaskey@368 139 public ArrayData setEmpty(final long lo, final long hi) {
jlaskey@368 140 underlying.setEmpty(lo, hi);
jlaskey@368 141 return this;
jlaskey@368 142 }
jlaskey@368 143
jlaskey@368 144 @Override
attila@963 145 public Type getOptimisticType() {
attila@963 146 return underlying.getOptimisticType();
attila@963 147 }
attila@963 148
attila@963 149 @Override
jlaskey@3 150 public int getInt(final int index) {
jlaskey@3 151 return underlying.getInt(index);
jlaskey@3 152 }
jlaskey@3 153
jlaskey@3 154 @Override
attila@963 155 public int getIntOptimistic(final int index, final int programPoint) {
attila@963 156 return underlying.getIntOptimistic(index, programPoint);
attila@963 157 }
attila@963 158
attila@963 159 @Override
jlaskey@3 160 public long getLong(final int index) {
jlaskey@3 161 return underlying.getLong(index);
jlaskey@3 162 }
jlaskey@3 163
jlaskey@3 164 @Override
attila@963 165 public long getLongOptimistic(final int index, final int programPoint) {
attila@963 166 return underlying.getLongOptimistic(index, programPoint);
attila@963 167 }
attila@963 168
attila@963 169 @Override
jlaskey@3 170 public double getDouble(final int index) {
jlaskey@3 171 return underlying.getDouble(index);
jlaskey@3 172 }
jlaskey@3 173
jlaskey@3 174 @Override
attila@963 175 public double getDoubleOptimistic(final int index, final int programPoint) {
attila@963 176 return underlying.getDoubleOptimistic(index, programPoint);
attila@963 177 }
attila@963 178
attila@963 179 @Override
jlaskey@3 180 public Object getObject(final int index) {
jlaskey@3 181 return underlying.getObject(index);
jlaskey@3 182 }
jlaskey@3 183
jlaskey@3 184 @Override
jlaskey@3 185 public boolean has(final int index) {
jlaskey@3 186 return underlying.has(index);
jlaskey@3 187 }
jlaskey@3 188
jlaskey@3 189 @Override
jlaskey@3 190 public ArrayData delete(final int index) {
jlaskey@3 191 underlying = underlying.delete(index);
lagergren@1028 192 setLength(underlying.length);
jlaskey@3 193 return this;
jlaskey@3 194 }
jlaskey@3 195
jlaskey@3 196 @Override
jlaskey@3 197 public ArrayData delete(final long from, final long to) {
jlaskey@3 198 underlying = underlying.delete(from, to);
lagergren@1028 199 setLength(underlying.length);
jlaskey@3 200 return this;
jlaskey@3 201 }
jlaskey@3 202
jlaskey@3 203 @Override
lagergren@1028 204 public ArrayData convert(final Class<?> type) {
jlaskey@3 205 underlying = underlying.convert(type);
lagergren@1028 206 setLength(underlying.length);
jlaskey@3 207 return this;
jlaskey@3 208 }
jlaskey@3 209
jlaskey@3 210 @Override
jlaskey@3 211 public Object pop() {
jlaskey@3 212 final Object value = underlying.pop();
lagergren@1028 213 setLength(underlying.length);
jlaskey@3 214
jlaskey@3 215 return value;
jlaskey@3 216 }
jlaskey@3 217
jlaskey@3 218 @Override
jlaskey@3 219 public long nextIndex(final long index) {
jlaskey@3 220 return underlying.nextIndex(index);
jlaskey@3 221 }
jlaskey@3 222
jlaskey@3 223 static Object convertUndefinedValue(final Class<?> targetType) {
jlaskey@3 224 return invoke(Bootstrap.getLinkerServices().getTypeConverter(Undefined.class, targetType),
jlaskey@3 225 ScriptRuntime.UNDEFINED);
jlaskey@3 226 }
jlaskey@3 227 }

mercurial