Fri, 31 Oct 2014 20:17:42 -0700
Merge
src/jdk/nashorn/internal/runtime/arrays/NoTypeArrayData.java | file | annotate | diff | comparison | revisions |
1.1 --- a/bin/runopt.sh Wed Oct 29 10:50:44 2014 -0700 1.2 +++ b/bin/runopt.sh Fri Oct 31 20:17:42 2014 -0700 1.3 @@ -28,14 +28,35 @@ 1.4 # known flags for performance for the current configration 1.5 ########################################################################################### 1.6 1.7 +# Flags to enable assertions, we need the system assertions too, since 1.8 +# this script runs Nashorn in the BCP to override any nashorn.jar that might 1.9 +# reside in your $JAVA_HOME/jre/lib/ext/nashorn.jar 1.10 +# 1.11 +ENABLE_ASSERTIONS_FLAGS="-ea -esa" 1.12 + 1.13 # Flags to instrument lambdaform computation, caching, interpretation and compilation 1.14 # Default compile threshold for lambdaforms is 30 1.15 -#FLAGS="-Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=3 -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true -Djava.lang.invoke.MethodHandle.TRACE_INTERPRETER=true" 1.16 - 1.17 +# 1.18 +#LAMBDAFORM_FLAGS="\ 1.19 +# -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=3 \ 1.20 +# -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true \ 1.21 +# -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true \ 1.22 +# -Djava.lang.invoke.MethodHandle.TRACE_INTERPRETER=true" 1.23 1.24 # Flags to run trusted tests from the Nashorn test suite 1.25 -#FLAGS="-Djava.security.manager -Djava.security.policy=../build/nashorn.policy -Dnashorn.debug" 1.26 +# 1.27 +#TRUSTED_TEST_FLAGS="\ 1.28 +#-Djava.security.manager \ 1.29 +#-Djava.security.policy=../build/nashorn.policy -Dnashorn.debug" 1.30 1.31 +# Testing out new code optimizations using the generic hotspot "new code" parameter 1.32 +# 1.33 +#USE_NEW_CODE_FLAGS=-XX:+UnlockDiagnosticVMOptions -XX:+UseNewCode 1.34 + 1.35 +# 1.36 +#-Dnashorn.typeInfo.disabled=false \ 1.37 +# and for Nashorn options: 1.38 +# --class-cache-size=0 --persistent-code-cache=false 1.39 1.40 # Unique timestamped file name for JFR recordings. For JFR, we also have to 1.41 # crank up the stack cutoff depth to 1024, because of ridiculously long lambda form 1.42 @@ -46,8 +67,42 @@ 1.43 # can go (10 ms on most platforms). The default is normally higher. The increased 1.44 # sampling overhead is usually negligible for Nashorn runs, but the data is better 1.45 1.46 -JFR_FILENAME="./nashorn_$(date|sed "s/ /_/g"|sed "s/:/_/g").jfr" 1.47 +if [ -z $JFR_FILENAME ]; then 1.48 + JFR_FILENAME="./nashorn_$(date|sed "s/ /_/g"|sed "s/:/_/g").jfr" 1.49 +fi 1.50 1.51 +# Flight recorder 1.52 +# 1.53 +# see above - already in place, copy the flags down here to disable 1.54 +ENABLE_FLIGHT_RECORDER_FLAGS="\ 1.55 + -XX:+UnlockCommercialFeatures \ 1.56 + -XX:+FlightRecorder \ 1.57 + -XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=$JFR_FILENAME,stackdepth=1024" 1.58 + 1.59 +# Type specialization and math intrinsic replacement should be enabled by default in 8u20 and nine, 1.60 +# keeping this flag around for experimental reasons. Replace + with - to switch it off 1.61 +# 1.62 +#ENABLE_TYPE_SPECIALIZATION_FLAGS=-XX:+UseTypeSpeculation 1.63 + 1.64 +# Same with math intrinsics. They should be enabled by default in 8u20 and 9, so 1.65 +# this disables them if needed 1.66 +# 1.67 +#DISABLE_MATH_INTRINSICS_FLAGS=-XX:-UseMathExactIntrinsics 1.68 + 1.69 +# Add timing to time the compilation phases. 1.70 +#ENABLE_TIME_FLAGS=--log=time 1.71 + 1.72 +# Add ShowHiddenFrames to get lambda form internals on the stack traces 1.73 +#ENABLE_SHOW_HIDDEN_FRAMES_FLAGS=-XX:+ShowHiddenFrames 1.74 + 1.75 +# Add print optoassembly to get an asm dump. This requires 1) a debug build, not product, 1.76 +# That tired compilation is switched off, for C2 only output and that the number of 1.77 +# compiler threads is set to 1 for determinsm. 1.78 +# 1.79 +#PRINT_ASM_FLAGS=-XX:+PrintOptoAssembly -XX:-TieredCompilation -XX:CICompilerCount=1 \ 1.80 + 1.81 +# Tier compile threasholds. Default value is 10. (1-100 is useful for experiments) 1.82 +#TIER_COMPILATION_THRESHOLD_FLAGS=-XX:IncreaseFirstTierCompileThresholdAt=10 1.83 1.84 # Directory where to look for nashorn.jar in a dist folder. The default is "..", assuming 1.85 # that we run the script from the make dir 1.86 @@ -59,49 +114,23 @@ 1.87 # nashorn.jar in $JAVA_HOME/jre/lib/ext. Thus, we also need -esa, as assertions in 1.88 # nashorn count as system assertions in this configuration 1.89 1.90 +# Type profiling default level is 111, 222 adds some compile time, but is faster 1.91 + 1.92 $JAVA_HOME/bin/java \ 1.93 -$FLAGS \ 1.94 --ea \ 1.95 --esa \ 1.96 +$ENABLE_ASSERTIONS_FLAGS \ 1.97 +$LAMBDAFORM_FLAGS \ 1.98 +$TRUSTED_FLAGS \ 1.99 +$USE_NEW_CODE_FLAGS \ 1.100 +$ENABLE_SHOW_HIDDEN_FRAMES_FLAGS \ 1.101 +$ENABLE_FLIGHT_RECORDER_FLAGS \ 1.102 +$ENABLE_TYPE_SPECIALIZATION_FLAGS \ 1.103 +$TIERED_COMPILATION_THRESOLD_FLAGS \ 1.104 +$DISABLE_MATH_INTRINSICS_FLAGS \ 1.105 +$PRINT_ASM_FLAGS \ 1.106 -Xbootclasspath/p:$NASHORN_JAR \ 1.107 -Xms2G -Xmx2G \ 1.108 +-XX:TypeProfileLevel=222 \ 1.109 -cp $CLASSPATH:../build/test/classes/ \ 1.110 -jdk.nashorn.tools.Shell ${@} 1.111 +jdk.nashorn.tools.Shell $ENABLE_TIME_FLAGS ${@} 1.112 1.113 -# Below are flags that may come in handy, but aren't used for default runs 1.114 1.115 - 1.116 -# Type profiling default level is 111, 222 adds some compile time, but produces better code. 1.117 -# -XX:TypeProfileLevel=222 \ 1.118 - 1.119 - 1.120 -# Testing out new code optimizations using the generic hotspot "new code" parameter 1.121 -#-XX:+UnlockDiagnosticVMOptions \ 1.122 -#-XX:+UseNewCode \ 1.123 - 1.124 - 1.125 -# Type specialization and math intrinsic replacement should be enabled by default in 8u20 and nine, 1.126 -# keeping this flag around for experimental reasons. Replace + with - to switch it off 1.127 -#-XX:+UseTypeSpeculation \ 1.128 - 1.129 - 1.130 -# Same with math intrinsics. They should be enabled by default in 8u20 and 9 1.131 -#-XX:+UseMathExactIntrinsics \ 1.132 - 1.133 - 1.134 -# Add -Dnashorn.time to time the compilation phases. 1.135 -#-Dnashorn.time \ 1.136 - 1.137 - 1.138 -# Add ShowHiddenFrames to get lambda form internals on the stack traces 1.139 -#-XX:+ShowHiddenFrames \ 1.140 - 1.141 - 1.142 -# Add print optoassembly to get an asm dump. This requires 1) a debug build, not product, 1.143 -# That tired compilation is switched off, for C2 only output and that the number of 1.144 -# compiler threads is set to 1 for determinsm. 1.145 -#-XX:+PrintOptoAssembly -XX:-TieredCompilation -XX:CICompilerCount=1 \ 1.146 - 1.147 -# Tier compile threasholds. Default value is 10. (1-100 is useful for experiments) 1.148 -# -XX:IncreaseFirstTierCompileThresholdAt=XX 1.149 -
2.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Oct 29 10:50:44 2014 -0700 2.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Fri Oct 31 20:17:42 2014 -0700 2.3 @@ -208,6 +208,8 @@ 2.4 private static final Type ITERATOR_TYPE = Type.typeFor(ITERATOR_CLASS); 2.5 private static final Type EXCEPTION_TYPE = Type.typeFor(CompilerConstants.EXCEPTION_PREFIX.type()); 2.6 2.7 + private static final Integer INT_ZERO = Integer.valueOf(0); 2.8 + 2.9 /** Constant data & installation. The only reason the compiler keeps this is because it is assigned 2.10 * by reflection in class installation */ 2.11 private final Compiler compiler; 2.12 @@ -3817,7 +3819,12 @@ 2.13 2.14 private void doSHR() { 2.15 // TODO: make SHR optimistic 2.16 - method.shr().convert(Type.LONG).load(JSType.MAX_UINT).and(); 2.17 + method.shr(); 2.18 + toUint(); 2.19 + } 2.20 + 2.21 + private void toUint() { 2.22 + JSType.TO_UINT32_I.invoke(method); 2.23 } 2.24 2.25 private void loadASSIGN_SUB(final BinaryNode binaryNode) { 2.26 @@ -3879,8 +3886,18 @@ 2.27 } 2.28 2.29 private void loadBIT_OR(final BinaryNode binaryNode) { 2.30 - loadBinaryOperands(binaryNode); 2.31 - method.or(); 2.32 + // Optimize x|0 to (int)x 2.33 + if (isRhsZero(binaryNode)) { 2.34 + loadExpressionAsType(binaryNode.lhs(), Type.INT); 2.35 + } else { 2.36 + loadBinaryOperands(binaryNode); 2.37 + method.or(); 2.38 + } 2.39 + } 2.40 + 2.41 + private static boolean isRhsZero(final BinaryNode binaryNode) { 2.42 + final Expression rhs = binaryNode.rhs(); 2.43 + return rhs instanceof LiteralNode && INT_ZERO.equals(((LiteralNode)rhs).getValue()); 2.44 } 2.45 2.46 private void loadBIT_XOR(final BinaryNode binaryNode) { 2.47 @@ -3957,8 +3974,14 @@ 2.48 } 2.49 2.50 private void loadSHR(final BinaryNode binaryNode) { 2.51 - loadBinaryOperands(binaryNode); 2.52 - doSHR(); 2.53 + // Optimize x >>> 0 to (uint)x 2.54 + if (isRhsZero(binaryNode)) { 2.55 + loadExpressionAsType(binaryNode.lhs(), Type.INT); 2.56 + toUint(); 2.57 + } else { 2.58 + loadBinaryOperands(binaryNode); 2.59 + doSHR(); 2.60 + } 2.61 } 2.62 2.63 private void loadSUB(final BinaryNode binaryNode, final TypeBounds resultBounds) {
3.1 --- a/src/jdk/nashorn/internal/codegen/FoldConstants.java Wed Oct 29 10:50:44 2014 -0700 3.2 +++ b/src/jdk/nashorn/internal/codegen/FoldConstants.java Fri Oct 31 20:17:42 2014 -0700 3.3 @@ -291,7 +291,7 @@ 3.4 value = lhs.getNumber() - rhs.getNumber(); 3.5 break; 3.6 case SHR: 3.7 - return LiteralNode.newInstance(token, finish, (lhs.getInt32() >>> rhs.getInt32()) & JSType.MAX_UINT); 3.8 + return LiteralNode.newInstance(token, finish, JSType.toUint32(lhs.getInt32() >>> rhs.getInt32())); 3.9 case SAR: 3.10 return LiteralNode.newInstance(token, finish, lhs.getInt32() >> rhs.getInt32()); 3.11 case SHL:
4.1 --- a/src/jdk/nashorn/internal/codegen/SpillObjectCreator.java Wed Oct 29 10:50:44 2014 -0700 4.2 +++ b/src/jdk/nashorn/internal/codegen/SpillObjectCreator.java Fri Oct 31 20:17:42 2014 -0700 4.3 @@ -88,7 +88,7 @@ 4.4 final Property property = propertyMap.findProperty(key); 4.5 if (property != null) { 4.6 // normal property key 4.7 - property.setCurrentType(JSType.unboxedFieldType(constantValue)); 4.8 + property.setType(JSType.unboxedFieldType(constantValue)); 4.9 final int slot = property.getSlot(); 4.10 if (!OBJECT_FIELDS_ONLY && constantValue instanceof Number) { 4.11 jpresetValues[slot] = ObjectClassGenerator.pack((Number)constantValue);
5.1 --- a/src/jdk/nashorn/internal/codegen/TypeEvaluator.java Wed Oct 29 10:50:44 2014 -0700 5.2 +++ b/src/jdk/nashorn/internal/codegen/TypeEvaluator.java Fri Oct 31 20:17:42 2014 -0700 5.3 @@ -117,7 +117,7 @@ 5.4 } 5.5 5.6 final Property property = find.getProperty(); 5.7 - final Class<?> propertyClass = property.getCurrentType(); 5.8 + final Class<?> propertyClass = property.getType(); 5.9 if (propertyClass == null) { 5.10 // propertyClass == null means its value is Undefined. It is probably not initialized yet, so we won't make 5.11 // a type assumption yet.
6.1 --- a/src/jdk/nashorn/internal/codegen/types/Type.java Wed Oct 29 10:50:44 2014 -0700 6.2 +++ b/src/jdk/nashorn/internal/codegen/types/Type.java Fri Oct 31 20:17:42 2014 -0700 6.3 @@ -586,6 +586,7 @@ 6.4 public int getSlots() { 6.5 return slots; 6.6 } 6.7 + 6.8 /** 6.9 * Returns the widest or most common of two types 6.10 * 6.11 @@ -609,6 +610,18 @@ 6.12 } 6.13 6.14 /** 6.15 + * Returns the widest or most common of two types, given as classes 6.16 + * 6.17 + * @param type0 type one 6.18 + * @param type1 type two 6.19 + * 6.20 + * @return the widest type 6.21 + */ 6.22 + public static Class<?> widest(final Class<?> type0, final Class<?> type1) { 6.23 + return widest(Type.typeFor(type0), Type.typeFor(type1)).getTypeClass(); 6.24 + } 6.25 + 6.26 + /** 6.27 * When doing widening for return types of a function or a ternary operator, it is not valid to widen a boolean to 6.28 * anything other than object. Note that this wouldn't be necessary if {@code Type.widest} did not allow 6.29 * boolean-to-number widening. Eventually, we should address it there, but it affects too many other parts of the
7.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Wed Oct 29 10:50:44 2014 -0700 7.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Fri Oct 31 20:17:42 2014 -0700 7.3 @@ -33,6 +33,7 @@ 7.4 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.arrayLikeIterator; 7.5 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.reverseArrayLikeIterator; 7.6 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT; 7.7 + 7.8 import java.lang.invoke.MethodHandle; 7.9 import java.lang.invoke.SwitchPoint; 7.10 import java.util.ArrayList; 7.11 @@ -92,9 +93,10 @@ 7.12 private static final Object CALL_CMP = new Object(); 7.13 private static final Object TO_LOCALE_STRING = new Object(); 7.14 7.15 - private SwitchPoint lengthMadeNotWritableSwitchPoint; 7.16 - private PushLinkLogic pushLinkLogic; 7.17 - private PopLinkLogic popLinkLogic; 7.18 + private SwitchPoint lengthMadeNotWritableSwitchPoint; 7.19 + private PushLinkLogic pushLinkLogic; 7.20 + private PopLinkLogic popLinkLogic; 7.21 + private ConcatLinkLogic concatLinkLogic; 7.22 7.23 /** 7.24 * Index for the modification SwitchPoint that triggers when length 7.25 @@ -130,7 +132,9 @@ 7.26 this(ArrayData.allocate(array.length)); 7.27 7.28 ArrayData arrayData = this.getArray(); 7.29 - arrayData.ensure(array.length - 1); 7.30 + if (array.length > 0) { 7.31 + arrayData.ensure(array.length - 1); 7.32 + } 7.33 7.34 for (int index = 0; index < array.length; index++) { 7.35 final Object value = array[index]; 7.36 @@ -266,7 +270,7 @@ 7.37 7.38 @Override 7.39 public Object getLength() { 7.40 - final long length = getArray().length() & JSType.MAX_UINT; 7.41 + final long length = JSType.toUint32(getArray().length()); 7.42 if(length < Integer.MAX_VALUE) { 7.43 return (int)length; 7.44 } 7.45 @@ -476,7 +480,7 @@ 7.46 @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE) 7.47 public static Object length(final Object self) { 7.48 if (isArray(self)) { 7.49 - return ((ScriptObject) self).getArray().length() & JSType.MAX_UINT; 7.50 + return JSType.toUint32(((ScriptObject) self).getArray().length()); 7.51 } 7.52 7.53 return 0; 7.54 @@ -757,12 +761,86 @@ 7.55 * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] ) 7.56 * 7.57 * @param self self reference 7.58 + * @param arg argument 7.59 + * @return resulting NativeArray 7.60 + */ 7.61 + @SpecializedFunction(linkLogic=ConcatLinkLogic.class) 7.62 + public static NativeArray concat(final Object self, final int arg) { 7.63 + final ContinuousArrayData newData = getContinuousArrayDataCCE(self, Integer.class).copy(); //get at least an integer data copy of this data 7.64 + newData.fastPush(arg); //add an integer to its end 7.65 + return new NativeArray(newData); 7.66 + } 7.67 + 7.68 + /** 7.69 + * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] ) 7.70 + * 7.71 + * @param self self reference 7.72 + * @param arg argument 7.73 + * @return resulting NativeArray 7.74 + */ 7.75 + @SpecializedFunction(linkLogic=ConcatLinkLogic.class) 7.76 + public static NativeArray concat(final Object self, final long arg) { 7.77 + final ContinuousArrayData newData = getContinuousArrayDataCCE(self, Long.class).copy(); //get at least a long array data copy of this data 7.78 + newData.fastPush(arg); //add a long at the end 7.79 + return new NativeArray(newData); 7.80 + } 7.81 + 7.82 + /** 7.83 + * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] ) 7.84 + * 7.85 + * @param self self reference 7.86 + * @param arg argument 7.87 + * @return resulting NativeArray 7.88 + */ 7.89 + @SpecializedFunction(linkLogic=ConcatLinkLogic.class) 7.90 + public static NativeArray concat(final Object self, final double arg) { 7.91 + final ContinuousArrayData newData = getContinuousArrayDataCCE(self, Double.class).copy(); //get at least a number array data copy of this data 7.92 + newData.fastPush(arg); //add a double at the end 7.93 + return new NativeArray(newData); 7.94 + } 7.95 + 7.96 + /** 7.97 + * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] ) 7.98 + * 7.99 + * @param self self reference 7.100 + * @param arg argument 7.101 + * @return resulting NativeArray 7.102 + */ 7.103 + @SpecializedFunction(linkLogic=ConcatLinkLogic.class) 7.104 + public static NativeArray concat(final Object self, final Object arg) { 7.105 + //arg is [NativeArray] of same type. 7.106 + final ContinuousArrayData selfData = getContinuousArrayDataCCE(self); 7.107 + final ContinuousArrayData newData; 7.108 + 7.109 + if (arg instanceof NativeArray) { 7.110 + final ContinuousArrayData argData = (ContinuousArrayData)((NativeArray)arg).getArray(); 7.111 + if (argData.isEmpty()) { 7.112 + newData = selfData.copy(); 7.113 + } else if (selfData.isEmpty()) { 7.114 + newData = argData.copy(); 7.115 + } else { 7.116 + final Class<?> widestElementType = selfData.widest(argData).getBoxedElementType(); 7.117 + newData = ((ContinuousArrayData)selfData.convert(widestElementType)).fastConcat((ContinuousArrayData)argData.convert(widestElementType)); 7.118 + } 7.119 + } else { 7.120 + newData = getContinuousArrayDataCCE(self, Object.class).copy(); 7.121 + newData.fastPush(arg); 7.122 + } 7.123 + 7.124 + return new NativeArray(newData); 7.125 + } 7.126 + 7.127 + /** 7.128 + * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] ) 7.129 + * 7.130 + * @param self self reference 7.131 * @param args arguments 7.132 * @return resulting NativeArray 7.133 */ 7.134 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 7.135 public static NativeArray concat(final Object self, final Object... args) { 7.136 final ArrayList<Object> list = new ArrayList<>(); 7.137 + 7.138 concatToList(list, Global.toObject(self)); 7.139 7.140 for (final Object obj : args) { 7.141 @@ -1692,13 +1770,15 @@ 7.142 return pushLinkLogic == null ? new PushLinkLogic(this) : pushLinkLogic; 7.143 } else if (clazz == PopLinkLogic.class) { 7.144 return popLinkLogic == null ? new PopLinkLogic(this) : pushLinkLogic; 7.145 + } else if (clazz == ConcatLinkLogic.class) { 7.146 + return concatLinkLogic == null ? new ConcatLinkLogic(this) : concatLinkLogic; 7.147 } 7.148 return null; 7.149 } 7.150 7.151 @Override 7.152 public boolean hasPerInstanceAssumptions() { 7.153 - return true; //length switchpoint 7.154 + return true; //length writable switchpoint 7.155 } 7.156 7.157 /** 7.158 @@ -1798,6 +1878,40 @@ 7.159 } 7.160 7.161 /** 7.162 + * This is linker logic for optimistic concatenations 7.163 + */ 7.164 + private static final class ConcatLinkLogic extends ArrayLinkLogic { 7.165 + private ConcatLinkLogic(final NativeArray array) { 7.166 + super(array); 7.167 + } 7.168 + 7.169 + @Override 7.170 + public boolean canLink(final Object self, final CallSiteDescriptor desc, final LinkRequest request) { 7.171 + final Object[] args = request.getArguments(); 7.172 + 7.173 + if (args.length != 3) { //single argument check 7.174 + return false; 7.175 + } 7.176 + 7.177 + final ContinuousArrayData selfData = getContinuousArrayData(self); 7.178 + if (selfData == null) { 7.179 + return false; 7.180 + } 7.181 + 7.182 + final Object arg = args[2]; 7.183 + //args[2] continuousarray or non arraydata, let past non array datas 7.184 + if (arg instanceof NativeArray) { 7.185 + final ContinuousArrayData argData = getContinuousArrayData(arg); 7.186 + if (argData == null) { 7.187 + return false; 7.188 + } 7.189 + } 7.190 + 7.191 + return true; 7.192 + } 7.193 + } 7.194 + 7.195 + /** 7.196 * This is linker logic for optimistic pushes 7.197 */ 7.198 private static final class PushLinkLogic extends ArrayLinkLogic { 7.199 @@ -1864,6 +1978,14 @@ 7.200 throw new ClassCastException(); 7.201 } 7.202 7.203 + private static final ContinuousArrayData getContinuousArrayDataCCE(final Object self) { 7.204 + try { 7.205 + return (ContinuousArrayData)((NativeArray)self).getArray(); 7.206 + } catch (final NullPointerException e) { 7.207 + throw new ClassCastException(); 7.208 + } 7.209 + } 7.210 + 7.211 private static final ContinuousArrayData getContinuousArrayDataCCE(final Object self, final Class<?> elementType) { 7.212 try { 7.213 return (ContinuousArrayData)((NativeArray)self).getArray(elementType); //ensure element type can fit "elementType"
8.1 --- a/src/jdk/nashorn/internal/objects/NativeDataView.java Wed Oct 29 10:50:44 2014 -0700 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeDataView.java Fri Oct 31 20:17:42 2014 -0700 8.3 @@ -27,6 +27,7 @@ 8.4 import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError; 8.5 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 8.6 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 8.7 + 8.8 import java.nio.ByteBuffer; 8.9 import java.nio.ByteOrder; 8.10 import jdk.nashorn.internal.objects.annotations.Attribute; 8.11 @@ -432,7 +433,7 @@ 8.12 @SpecializedFunction 8.13 public static long getUint32(final Object self, final int byteOffset) { 8.14 try { 8.15 - return JSType.MAX_UINT & getBuffer(self, false).getInt(JSType.toInt32(byteOffset)); 8.16 + return JSType.toUint32(getBuffer(self, false).getInt(JSType.toInt32(byteOffset))); 8.17 } catch (final IllegalArgumentException iae) { 8.18 throw rangeError(iae, "dataview.offset"); 8.19 } 8.20 @@ -449,7 +450,7 @@ 8.21 @SpecializedFunction 8.22 public static long getUint32(final Object self, final int byteOffset, final boolean littleEndian) { 8.23 try { 8.24 - return JSType.MAX_UINT & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset)); 8.25 + return JSType.toUint32(getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset))); 8.26 } catch (final IllegalArgumentException iae) { 8.27 throw rangeError(iae, "dataview.offset"); 8.28 }
9.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java Wed Oct 29 10:50:44 2014 -0700 9.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java Fri Oct 31 20:17:42 2014 -0700 9.3 @@ -1045,7 +1045,8 @@ 9.4 9.5 // ECMA 15.9.1.2 TimeWithinDay (t) 9.6 private static double timeWithinDay(final double t) { 9.7 - return t % msPerDay; 9.8 + final double val = t % msPerDay; 9.9 + return val < 0? val + msPerDay : val; 9.10 } 9.11 9.12 // ECMA 15.9.1.3 InLeapYear (t)
10.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat32Array.java Wed Oct 29 10:50:44 2014 -0700 10.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat32Array.java Fri Oct 31 20:17:42 2014 -0700 10.3 @@ -90,6 +90,11 @@ 10.4 } 10.5 10.6 @Override 10.7 + public Class<?> getBoxedElementType() { 10.8 + return Double.class; 10.9 + } 10.10 + 10.11 + @Override 10.12 protected MethodHandle getGetElem() { 10.13 return GET_ELEM; 10.14 }
11.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat64Array.java Wed Oct 29 10:50:44 2014 -0700 11.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat64Array.java Fri Oct 31 20:17:42 2014 -0700 11.3 @@ -99,6 +99,11 @@ 11.4 return double.class; 11.5 } 11.6 11.7 + @Override 11.8 + public Class<?> getBoxedElementType() { 11.9 + return Double.class; 11.10 + } 11.11 + 11.12 private double getElem(final int index) { 11.13 try { 11.14 return nb.get(index);
12.1 --- a/src/jdk/nashorn/internal/objects/NativeInt16Array.java Wed Oct 29 10:50:44 2014 -0700 12.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt16Array.java Fri Oct 31 20:17:42 2014 -0700 12.3 @@ -100,6 +100,11 @@ 12.4 return int.class; 12.5 } 12.6 12.7 + @Override 12.8 + public Class<?> getBoxedElementType() { 12.9 + return Integer.class; 12.10 + } 12.11 + 12.12 private int getElem(final int index) { 12.13 try { 12.14 return nb.get(index);
13.1 --- a/src/jdk/nashorn/internal/objects/NativeInt32Array.java Wed Oct 29 10:50:44 2014 -0700 13.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt32Array.java Fri Oct 31 20:17:42 2014 -0700 13.3 @@ -118,6 +118,11 @@ 13.4 } 13.5 13.6 @Override 13.7 + public Class<?> getBoxedElementType() { 13.8 + return Integer.class; 13.9 + } 13.10 + 13.11 + @Override 13.12 public int getInt(final int index) { 13.13 return getElem(index); 13.14 }
14.1 --- a/src/jdk/nashorn/internal/objects/NativeInt8Array.java Wed Oct 29 10:50:44 2014 -0700 14.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt8Array.java Fri Oct 31 20:17:42 2014 -0700 14.3 @@ -98,6 +98,11 @@ 14.4 return int.class; 14.5 } 14.6 14.7 + @Override 14.8 + public Class<?> getBoxedElementType() { 14.9 + return Integer.class; 14.10 + } 14.11 + 14.12 private int getElem(final int index) { 14.13 try { 14.14 return nb.get(index);
15.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Wed Oct 29 10:50:44 2014 -0700 15.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Fri Oct 31 20:17:42 2014 -0700 15.3 @@ -28,7 +28,6 @@ 15.4 import static jdk.nashorn.internal.lookup.Lookup.MH; 15.5 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 15.6 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 15.7 - 15.8 import java.lang.invoke.MethodHandle; 15.9 import java.lang.invoke.MethodHandles; 15.10 import java.lang.invoke.MethodType; 15.11 @@ -673,7 +672,7 @@ 15.12 for (final Property prop : properties) { 15.13 if (prop.isEnumerable()) { 15.14 final Object value = sourceObj.get(prop.getKey()); 15.15 - prop.setCurrentType(Object.class); 15.16 + prop.setType(Object.class); 15.17 prop.setValue(sourceObj, sourceObj, value, false); 15.18 propList.add(prop); 15.19 }
16.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java Wed Oct 29 10:50:44 2014 -0700 16.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java Fri Oct 31 20:17:42 2014 -0700 16.3 @@ -74,7 +74,7 @@ 16.4 @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE) 16.5 public static Object length(final Object self) { 16.6 if (self instanceof ScriptObject) { 16.7 - return ((ScriptObject)self).getArray().length() & JSType.MAX_UINT; 16.8 + return JSType.toUint32(((ScriptObject)self).getArray().length()); 16.9 } 16.10 16.11 return 0;
17.1 --- a/src/jdk/nashorn/internal/objects/NativeUint16Array.java Wed Oct 29 10:50:44 2014 -0700 17.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint16Array.java Fri Oct 31 20:17:42 2014 -0700 17.3 @@ -124,6 +124,11 @@ 17.4 } 17.5 17.6 @Override 17.7 + public Class<?> getBoxedElementType() { 17.8 + return Integer.class; 17.9 + } 17.10 + 17.11 + @Override 17.12 public int getInt(final int index) { 17.13 return getElem(index); 17.14 }
18.1 --- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java Wed Oct 29 10:50:44 2014 -0700 18.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java Fri Oct 31 20:17:42 2014 -0700 18.3 @@ -105,7 +105,7 @@ 18.4 18.5 private long getElem(final int index) { 18.6 try { 18.7 - return nb.get(index) & JSType.MAX_UINT; 18.8 + return JSType.toUint32(nb.get(index)); 18.9 } catch (final IndexOutOfBoundsException e) { 18.10 throw new ClassCastException(); //force relink - this works for unoptimistic too 18.11 } 18.12 @@ -133,6 +133,11 @@ 18.13 } 18.14 18.15 @Override 18.16 + public Class<?> getBoxedElementType() { 18.17 + return Integer.class; 18.18 + } 18.19 + 18.20 + @Override 18.21 public int getInt(final int index) { 18.22 return (int)getLong(index); 18.23 }
19.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8Array.java Wed Oct 29 10:50:44 2014 -0700 19.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8Array.java Fri Oct 31 20:17:42 2014 -0700 19.3 @@ -124,6 +124,11 @@ 19.4 } 19.5 19.6 @Override 19.7 + public Class<?> getBoxedElementType() { 19.8 + return Integer.class; 19.9 + } 19.10 + 19.11 + @Override 19.12 public int getInt(final int index) { 19.13 return getElem(index); 19.14 }
20.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java Wed Oct 29 10:50:44 2014 -0700 20.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java Fri Oct 31 20:17:42 2014 -0700 20.3 @@ -103,6 +103,11 @@ 20.4 return int.class; 20.5 } 20.6 20.7 + @Override 20.8 + public Class<?> getBoxedElementType() { 20.9 + return int.class; 20.10 + } 20.11 + 20.12 private int getElem(final int index) { 20.13 try { 20.14 return nb.get(index) & 0xff;
21.1 --- a/src/jdk/nashorn/internal/parser/JSONParser.java Wed Oct 29 10:50:44 2014 -0700 21.2 +++ b/src/jdk/nashorn/internal/parser/JSONParser.java Fri Oct 31 20:17:42 2014 -0700 21.3 @@ -32,7 +32,6 @@ 21.4 import static jdk.nashorn.internal.parser.TokenType.RBRACE; 21.5 import static jdk.nashorn.internal.parser.TokenType.RBRACKET; 21.6 import static jdk.nashorn.internal.parser.TokenType.STRING; 21.7 - 21.8 import java.util.ArrayList; 21.9 import java.util.List; 21.10 import jdk.nashorn.internal.ir.Expression;
22.1 --- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java Wed Oct 29 10:50:44 2014 -0700 22.2 +++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java Fri Oct 31 20:17:42 2014 -0700 22.3 @@ -145,13 +145,6 @@ 22.4 transient MethodHandle objectSetter; 22.5 22.6 /** 22.7 - * Current type of this object, in object only mode, this is an Object.class. In dual-fields mode 22.8 - * null means undefined, and primitive types are allowed. The reason a special type is used for 22.9 - * undefined, is that are no bits left to represent it in primitive types 22.10 - */ 22.11 - private Class<?> currentType; 22.12 - 22.13 - /** 22.14 * Delegate constructor for bound properties. This is used for properties created by 22.15 * {@link ScriptRuntime#mergeScope} and the Nashorn {@code Object.bindProperties} method. 22.16 * The former is used to add a script's defined globals to the current global scope while 22.17 @@ -171,7 +164,7 @@ 22.18 this.objectSetter = bindTo(property.objectSetter, delegate); 22.19 property.GETTER_CACHE = new MethodHandle[NOOF_TYPES]; 22.20 // Properties created this way are bound to a delegate 22.21 - setCurrentType(property.getCurrentType()); 22.22 + setType(property.getType()); 22.23 } 22.24 22.25 /** 22.26 @@ -248,7 +241,7 @@ 22.27 objectGetter = getter.type() != Lookup.GET_OBJECT_TYPE ? MH.asType(getter, Lookup.GET_OBJECT_TYPE) : getter; 22.28 objectSetter = setter != null && setter.type() != Lookup.SET_OBJECT_TYPE ? MH.asType(setter, Lookup.SET_OBJECT_TYPE) : setter; 22.29 22.30 - setCurrentType(OBJECT_FIELDS_ONLY ? Object.class : getterType); 22.31 + setType(OBJECT_FIELDS_ONLY ? Object.class : getterType); 22.32 } 22.33 22.34 /** 22.35 @@ -317,7 +310,7 @@ 22.36 */ 22.37 public AccessorProperty(final String key, final int flags, final Class<?> structure, final int slot, final Class<?> initialType) { 22.38 this(key, flags, structure, slot); 22.39 - setCurrentType(OBJECT_FIELDS_ONLY ? Object.class : initialType); 22.40 + setType(OBJECT_FIELDS_ONLY ? Object.class : initialType); 22.41 } 22.42 22.43 /** 22.44 @@ -330,13 +323,13 @@ 22.45 protected AccessorProperty(final AccessorProperty property, final Class<?> newType) { 22.46 super(property, property.getFlags()); 22.47 22.48 - this.GETTER_CACHE = newType != property.getCurrentType() ? new MethodHandle[NOOF_TYPES] : property.GETTER_CACHE; 22.49 + this.GETTER_CACHE = newType != property.getLocalType() ? new MethodHandle[NOOF_TYPES] : property.GETTER_CACHE; 22.50 this.primitiveGetter = property.primitiveGetter; 22.51 this.primitiveSetter = property.primitiveSetter; 22.52 this.objectGetter = property.objectGetter; 22.53 this.objectSetter = property.objectSetter; 22.54 22.55 - setCurrentType(newType); 22.56 + setType(newType); 22.57 } 22.58 22.59 /** 22.60 @@ -345,7 +338,7 @@ 22.61 * @param property source property 22.62 */ 22.63 protected AccessorProperty(final AccessorProperty property) { 22.64 - this(property, property.getCurrentType()); 22.65 + this(property, property.getLocalType()); 22.66 } 22.67 22.68 /** 22.69 @@ -354,7 +347,7 @@ 22.70 * @param initialValue initial value 22.71 */ 22.72 protected final void setInitialValue(final ScriptObject owner, final Object initialValue) { 22.73 - setCurrentType(JSType.unboxedFieldType(initialValue)); 22.74 + setType(JSType.unboxedFieldType(initialValue)); 22.75 if (initialValue instanceof Integer) { 22.76 invokeSetter(owner, ((Integer)initialValue).intValue()); 22.77 } else if (initialValue instanceof Long) { 22.78 @@ -370,7 +363,7 @@ 22.79 * Initialize the type of a property 22.80 */ 22.81 protected final void initializeType() { 22.82 - setCurrentType(OBJECT_FIELDS_ONLY ? Object.class : null); 22.83 + setType(OBJECT_FIELDS_ONLY ? Object.class : null); 22.84 } 22.85 22.86 private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException { 22.87 @@ -557,12 +550,12 @@ 22.88 } else { 22.89 getter = debug( 22.90 createGetter( 22.91 - getCurrentType(), 22.92 + getLocalType(), 22.93 type, 22.94 primitiveGetter, 22.95 objectGetter, 22.96 INVALID_PROGRAM_POINT), 22.97 - getCurrentType(), 22.98 + getLocalType(), 22.99 type, 22.100 "get"); 22.101 getterCache[i] = getter; 22.102 @@ -582,18 +575,18 @@ 22.103 22.104 return debug( 22.105 createGetter( 22.106 - getCurrentType(), 22.107 + getLocalType(), 22.108 type, 22.109 primitiveGetter, 22.110 objectGetter, 22.111 programPoint), 22.112 - getCurrentType(), 22.113 + getLocalType(), 22.114 type, 22.115 "get"); 22.116 } 22.117 22.118 private MethodHandle getOptimisticPrimitiveGetter(final Class<?> type, final int programPoint) { 22.119 - final MethodHandle g = getGetter(getCurrentType()); 22.120 + final MethodHandle g = getGetter(getLocalType()); 22.121 return MH.asType(OptimisticReturnFilters.filterOptimisticReturnValue(g, type, programPoint), g.type().changeReturnType(type)); 22.122 } 22.123 22.124 @@ -631,7 +624,7 @@ 22.125 } 22.126 22.127 private MethodHandle generateSetter(final Class<?> forType, final Class<?> type) { 22.128 - return debug(createSetter(forType, type, primitiveSetter, objectSetter), getCurrentType(), type, "set"); 22.129 + return debug(createSetter(forType, type, primitiveSetter, objectSetter), getLocalType(), type, "set"); 22.130 } 22.131 22.132 /** 22.133 @@ -639,7 +632,7 @@ 22.134 * @return true if undefined 22.135 */ 22.136 protected final boolean isUndefined() { 22.137 - return getCurrentType() == null; 22.138 + return getLocalType() == null; 22.139 } 22.140 22.141 @Override 22.142 @@ -647,7 +640,7 @@ 22.143 checkUndeclared(); 22.144 22.145 final int typeIndex = getAccessorTypeIndex(type); 22.146 - final int currentTypeIndex = getAccessorTypeIndex(getCurrentType()); 22.147 + final int currentTypeIndex = getAccessorTypeIndex(getLocalType()); 22.148 22.149 //if we are asking for an object setter, but are still a primitive type, we might try to box it 22.150 MethodHandle mh; 22.151 @@ -656,13 +649,13 @@ 22.152 final PropertyMap newMap = getWiderMap(currentMap, newProperty); 22.153 22.154 final MethodHandle widerSetter = newProperty.getSetter(type, newMap); 22.155 - final Class<?> ct = getCurrentType(); 22.156 + final Class<?> ct = getLocalType(); 22.157 mh = MH.filterArguments(widerSetter, 0, MH.insertArguments(debugReplace(ct, type, currentMap, newMap) , 1, newMap)); 22.158 if (ct != null && ct.isPrimitive() && !type.isPrimitive()) { 22.159 mh = ObjectClassGenerator.createGuardBoxedPrimitiveSetter(ct, generateSetter(ct, ct), mh); 22.160 } 22.161 } else { 22.162 - final Class<?> forType = isUndefined() ? type : getCurrentType(); 22.163 + final Class<?> forType = isUndefined() ? type : getLocalType(); 22.164 mh = generateSetter(!forType.isPrimitive() ? Object.class : forType, type); 22.165 } 22.166 22.167 @@ -681,24 +674,13 @@ 22.168 return false; 22.169 } 22.170 // Return true for currently undefined even if non-writable/configurable to allow initialization of ES6 CONST. 22.171 - return getCurrentType() == null || (getCurrentType() != Object.class && (isConfigurable() || isWritable())); 22.172 + return getLocalType() == null || (getLocalType() != Object.class && (isConfigurable() || isWritable())); 22.173 } 22.174 22.175 private boolean needsInvalidator(final int typeIndex, final int currentTypeIndex) { 22.176 return canChangeType() && typeIndex > currentTypeIndex; 22.177 } 22.178 22.179 - @Override 22.180 - public final void setCurrentType(final Class<?> currentType) { 22.181 - assert currentType != boolean.class : "no boolean storage support yet - fix this"; 22.182 - this.currentType = currentType == null ? null : currentType.isPrimitive() ? currentType : Object.class; 22.183 - } 22.184 - 22.185 - @Override 22.186 - public Class<?> getCurrentType() { 22.187 - return currentType; 22.188 - } 22.189 - 22.190 private MethodHandle debug(final MethodHandle mh, final Class<?> forType, final Class<?> type, final String tag) { 22.191 if (!Context.DEBUG || !Global.hasInstance()) { 22.192 return mh;
23.1 --- a/src/jdk/nashorn/internal/runtime/ECMAException.java Wed Oct 29 10:50:44 2014 -0700 23.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAException.java Fri Oct 31 20:17:42 2014 -0700 23.3 @@ -96,15 +96,17 @@ 23.4 // If thrown object is an Error or sub-object like TypeError, then 23.5 // an ECMAException object has been already initialized at constructor. 23.6 if (thrown instanceof ScriptObject) { 23.7 - final ScriptObject sobj = (ScriptObject)thrown; 23.8 - final Object exception = getException(sobj); 23.9 + final Object exception = getException((ScriptObject)thrown); 23.10 if (exception instanceof ECMAException) { 23.11 - // copy over file name, line number and column number. 23.12 final ECMAException ee = (ECMAException)exception; 23.13 - ee.setFileName(fileName); 23.14 - ee.setLineNumber(line); 23.15 - ee.setColumnNumber(column); 23.16 - return ee; 23.17 + // Make sure exception has correct thrown reference because that's what will end up getting caught. 23.18 + if (ee.getThrown() == thrown) { 23.19 + // copy over file name, line number and column number. 23.20 + ee.setFileName(fileName); 23.21 + ee.setLineNumber(line); 23.22 + ee.setColumnNumber(column); 23.23 + return ee; 23.24 + } 23.25 } 23.26 } 23.27 23.28 @@ -154,7 +156,11 @@ 23.29 * @return a {@link ECMAException} 23.30 */ 23.31 public static Object getException(final ScriptObject errObj) { 23.32 - return errObj.get(ECMAException.EXCEPTION_PROPERTY); 23.33 + // Exclude inherited properties that may belong to errors in the prototype chain. 23.34 + if (errObj.hasOwnProperty(ECMAException.EXCEPTION_PROPERTY)) { 23.35 + return errObj.get(ECMAException.EXCEPTION_PROPERTY); 23.36 + } 23.37 + return null; 23.38 } 23.39 23.40 /**
24.1 --- a/src/jdk/nashorn/internal/runtime/FindProperty.java Wed Oct 29 10:50:44 2014 -0700 24.2 +++ b/src/jdk/nashorn/internal/runtime/FindProperty.java Fri Oct 31 20:17:42 2014 -0700 24.3 @@ -84,13 +84,18 @@ 24.4 * @return method handle for the getter 24.5 */ 24.6 public MethodHandle getGetter(final Class<?> type, final int programPoint, final LinkRequest request) { 24.7 - final MethodHandle getter; 24.8 + MethodHandle getter; 24.9 if (isValid(programPoint)) { 24.10 getter = property.getOptimisticGetter(type, programPoint); 24.11 } else { 24.12 getter = property.getGetter(type); 24.13 } 24.14 if (property instanceof UserAccessorProperty) { 24.15 + getter = MH.insertArguments(getter, 1, UserAccessorProperty.getINVOKE_UA_GETTER(type, programPoint)); 24.16 + if (isValid(programPoint) && type.isPrimitive()) { 24.17 + getter = MH.insertArguments(getter, 1, programPoint); 24.18 + } 24.19 + property.setType(type); 24.20 return insertAccessorsGetter((UserAccessorProperty) property, request, getter); 24.21 } 24.22 return getter; 24.23 @@ -111,7 +116,8 @@ 24.24 public MethodHandle getSetter(final Class<?> type, final boolean strict, final LinkRequest request) { 24.25 MethodHandle setter = property.getSetter(type, getOwner().getMap()); 24.26 if (property instanceof UserAccessorProperty) { 24.27 - setter = MH.insertArguments(setter, 1, strict ? property.getKey() : null); 24.28 + setter = MH.insertArguments(setter, 1, UserAccessorProperty.getINVOKE_UA_SETTER(type), strict ? property.getKey() : null); 24.29 + property.setType(type); 24.30 return insertAccessorsGetter((UserAccessorProperty) property, request, setter); 24.31 } 24.32
25.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Wed Oct 29 10:50:44 2014 -0700 25.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Fri Oct 31 20:17:42 2014 -0700 25.3 @@ -29,7 +29,6 @@ 25.4 import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY; 25.5 import static jdk.nashorn.internal.lookup.Lookup.MH; 25.6 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 25.7 - 25.8 import java.lang.invoke.MethodHandle; 25.9 import java.lang.invoke.MethodHandles; 25.10 import java.lang.reflect.Array; 25.11 @@ -115,6 +114,9 @@ 25.12 /** JavaScript compliant conversion function from double to int32 */ 25.13 public static final Call TO_INT32_D = staticCall(JSTYPE_LOOKUP, JSType.class, "toInt32", int.class, double.class); 25.14 25.15 + /** JavaScript compliant conversion function from int to uint32 */ 25.16 + public static final Call TO_UINT32_I = staticCall(JSTYPE_LOOKUP, JSType.class, "toUint32", long.class, int.class); 25.17 + 25.18 /** JavaScript compliant conversion function from Object to uint32 */ 25.19 public static final Call TO_UINT32 = staticCall(JSTYPE_LOOKUP, JSType.class, "toUint32", long.class, Object.class); 25.20 25.21 @@ -1002,6 +1004,16 @@ 25.22 } 25.23 25.24 /** 25.25 + * JavaScript compliant int to uint32 conversion 25.26 + * 25.27 + * @param num an int 25.28 + * @return a uint32 25.29 + */ 25.30 + public static long toUint32(final int num) { 25.31 + return num & MAX_UINT; 25.32 + } 25.33 + 25.34 + /** 25.35 * JavaScript compliant Object to uint16 conversion 25.36 * ECMA 9.7 ToUint16: (Unsigned 16 Bit Integer) 25.37 * 25.38 @@ -1776,6 +1788,23 @@ 25.39 } 25.40 25.41 /** 25.42 + * Returns the boxed version of a primitive class 25.43 + * @param clazz the class 25.44 + * @return the boxed type of clazz, or unchanged if not primitive 25.45 + */ 25.46 + public static Class<?> getBoxedClass(final Class<?> clazz) { 25.47 + if (clazz == int.class) { 25.48 + return Integer.class; 25.49 + } else if (clazz == long.class) { 25.50 + return Long.class; 25.51 + } else if (clazz == double.class) { 25.52 + return Double.class; 25.53 + } 25.54 + assert !clazz.isPrimitive(); 25.55 + return clazz; 25.56 + } 25.57 + 25.58 + /** 25.59 * Create a method handle constant of the correct primitive type 25.60 * for a constant object 25.61 * @param o object
26.1 --- a/src/jdk/nashorn/internal/runtime/Property.java Wed Oct 29 10:50:44 2014 -0700 26.2 +++ b/src/jdk/nashorn/internal/runtime/Property.java Fri Oct 31 20:17:42 2014 -0700 26.3 @@ -102,6 +102,13 @@ 26.4 /** Property field number or spill slot. */ 26.5 private final int slot; 26.6 26.7 + /** 26.8 + * Current type of this object, in object only mode, this is an Object.class. In dual-fields mode 26.9 + * null means undefined, and primitive types are allowed. The reason a special type is used for 26.10 + * undefined, is that are no bits left to represent it in primitive types 26.11 + */ 26.12 + private Class<?> type; 26.13 + 26.14 /** SwitchPoint that is invalidated when property is changed, optional */ 26.15 protected transient SwitchPoint builtinSwitchPoint; 26.16 26.17 @@ -536,7 +543,7 @@ 26.18 * <p> 26.19 * see {@link ObjectClassGenerator#createSetter(Class, Class, MethodHandle, MethodHandle)} 26.20 * if you are interested in the internal details of this. Note that if you 26.21 - * are running in default mode, with {@code -Dnashorn.fields.dual=true}, disabled, the setters 26.22 + * are running with {@code -Dnashorn.fields.objects=true}, the setters 26.23 * will currently never change, as all properties are represented as Object field, 26.24 * the Object fields are Initialized to {@code ScriptRuntime.UNDEFINED} and primitives are 26.25 * boxed/unboxed upon every access, which is not necessarily optimal 26.26 @@ -569,7 +576,7 @@ 26.27 26.28 @Override 26.29 public int hashCode() { 26.30 - final Class<?> type = getCurrentType(); 26.31 + final Class<?> type = getLocalType(); 26.32 return Objects.hashCode(this.key) ^ flags ^ getSlot() ^ (type == null ? 0 : type.hashCode()); 26.33 } 26.34 26.35 @@ -586,7 +593,7 @@ 26.36 final Property otherProperty = (Property)other; 26.37 26.38 return equalsWithoutType(otherProperty) && 26.39 - getCurrentType() == otherProperty.getCurrentType(); 26.40 + getLocalType() == otherProperty.getLocalType(); 26.41 } 26.42 26.43 boolean equalsWithoutType(final Property otherProperty) { 26.44 @@ -615,7 +622,7 @@ 26.45 */ 26.46 public final String toStringShort() { 26.47 final StringBuilder sb = new StringBuilder(); 26.48 - final Class<?> type = getCurrentType(); 26.49 + final Class<?> type = getLocalType(); 26.50 sb.append(getKey()).append(" (").append(type(type)).append(')'); 26.51 return sb.toString(); 26.52 } 26.53 @@ -632,7 +639,7 @@ 26.54 @Override 26.55 public String toString() { 26.56 final StringBuilder sb = new StringBuilder(); 26.57 - final Class<?> type = getCurrentType(); 26.58 + final Class<?> type = getLocalType(); 26.59 26.60 sb.append(indent(getKey(), 20)). 26.61 append(" id="). 26.62 @@ -656,20 +663,40 @@ 26.63 } 26.64 26.65 /** 26.66 - * Get the current type of this field. If you are not running with dual fields enabled, 26.67 + * Get the current type of this property. If you are running with object fields enabled, 26.68 * this will always be Object.class. See the value representation explanation in 26.69 * {@link Property#getSetter(Class, PropertyMap)} and {@link ObjectClassGenerator} 26.70 * for more information. 26.71 * 26.72 + * <p>Note that for user accessor properties, this returns the type of the last observed 26.73 + * value passed to or returned by a user accessor. Use {@link #getLocalType()} to always get 26.74 + * the type of the actual value stored in the property slot.</p> 26.75 + * 26.76 * @return current type of property, null means undefined 26.77 */ 26.78 - public abstract Class<?> getCurrentType(); 26.79 + public final Class<?> getType() { 26.80 + return type; 26.81 + } 26.82 26.83 /** 26.84 - * Reset the current type of this property 26.85 - * @param currentType new current type 26.86 + * Set the type of this property. 26.87 + * @param type new type 26.88 */ 26.89 - public abstract void setCurrentType(final Class<?> currentType); 26.90 + public final void setType(final Class<?> type) { 26.91 + assert type != boolean.class : "no boolean storage support yet - fix this"; 26.92 + this.type = type == null ? null : type.isPrimitive() ? type : Object.class; 26.93 + } 26.94 + 26.95 + /** 26.96 + * Get the type of the value in the local property slot. This returns the same as 26.97 + * {@link #getType()} for normal properties, but always returns {@code Object.class} 26.98 + * for {@link UserAccessorProperty}s as their local type is a pair of accessor references. 26.99 + * 26.100 + * @return the local property type 26.101 + */ 26.102 + protected Class<?> getLocalType() { 26.103 + return getType(); 26.104 + } 26.105 26.106 /** 26.107 * Check whether this Property can ever change its type. The default is false, and if
27.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Oct 29 10:50:44 2014 -0700 27.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Fri Oct 31 20:17:42 2014 -0700 27.3 @@ -84,7 +84,7 @@ 27.4 private transient WeakHashMap<Property, SoftReference<PropertyMap>> history; 27.5 27.6 /** History of prototypes, used to limit map duplication. */ 27.7 - private transient WeakHashMap<PropertyMap, SoftReference<PropertyMap>> protoHistory; 27.8 + private transient WeakHashMap<ScriptObject, SoftReference<PropertyMap>> protoHistory; 27.9 27.10 /** property listeners */ 27.11 private transient PropertyListeners listeners; 27.12 @@ -512,7 +512,7 @@ 27.13 assert sameType || 27.14 oldProperty instanceof AccessorProperty && 27.15 newProperty instanceof UserAccessorProperty : 27.16 - "arbitrary replaceProperty attempted " + sameType + " oldProperty=" + oldProperty.getClass() + " newProperty=" + newProperty.getClass() + " [" + oldProperty.getCurrentType() + " => " + newProperty.getCurrentType() + "]"; 27.17 + "arbitrary replaceProperty attempted " + sameType + " oldProperty=" + oldProperty.getClass() + " newProperty=" + newProperty.getClass() + " [" + oldProperty.getLocalType() + " => " + newProperty.getLocalType() + "]"; 27.18 27.19 newMap.flags = flags; 27.20 27.21 @@ -677,14 +677,14 @@ 27.22 /** 27.23 * Check prototype history for an existing property map with specified prototype. 27.24 * 27.25 - * @param parentMap New prototype object. 27.26 + * @param proto New prototype object. 27.27 * 27.28 * @return Existing {@link PropertyMap} or {@code null} if not found. 27.29 */ 27.30 - private PropertyMap checkProtoHistory(final PropertyMap parentMap) { 27.31 + private PropertyMap checkProtoHistory(final ScriptObject proto) { 27.32 final PropertyMap cachedMap; 27.33 if (protoHistory != null) { 27.34 - final SoftReference<PropertyMap> weakMap = protoHistory.get(parentMap); 27.35 + final SoftReference<PropertyMap> weakMap = protoHistory.get(proto); 27.36 cachedMap = (weakMap != null ? weakMap.get() : null); 27.37 } else { 27.38 cachedMap = null; 27.39 @@ -700,15 +700,15 @@ 27.40 /** 27.41 * Add a map to the prototype history. 27.42 * 27.43 - * @param parentMap Prototype to add (key.) 27.44 + * @param newProto Prototype to add (key.) 27.45 * @param newMap {@link PropertyMap} associated with prototype. 27.46 */ 27.47 - private void addToProtoHistory(final PropertyMap parentMap, final PropertyMap newMap) { 27.48 + private void addToProtoHistory(final ScriptObject newProto, final PropertyMap newMap) { 27.49 if (protoHistory == null) { 27.50 protoHistory = new WeakHashMap<>(); 27.51 } 27.52 27.53 - protoHistory.put(parentMap, new SoftReference<>(newMap)); 27.54 + protoHistory.put(newProto, new SoftReference<>(newMap)); 27.55 } 27.56 27.57 /** 27.58 @@ -883,8 +883,7 @@ 27.59 */ 27.60 public PropertyMap changeProto(final ScriptObject newProto) { 27.61 27.62 - final PropertyMap parentMap = newProto == null ? null : newProto.getMap(); 27.63 - final PropertyMap nextMap = checkProtoHistory(parentMap); 27.64 + final PropertyMap nextMap = checkProtoHistory(newProto); 27.65 if (nextMap != null) { 27.66 return nextMap; 27.67 } 27.68 @@ -894,7 +893,7 @@ 27.69 } 27.70 27.71 final PropertyMap newMap = new PropertyMap(this); 27.72 - addToProtoHistory(parentMap, newMap); 27.73 + addToProtoHistory(newProto, newMap); 27.74 27.75 return newMap; 27.76 }
28.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Oct 29 10:50:44 2014 -0700 28.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Oct 31 20:17:42 2014 -0700 28.3 @@ -692,8 +692,7 @@ 28.4 assert isValidArrayIndex(index) : "invalid array index"; 28.5 final long longIndex = ArrayIndex.toLongIndex(index); 28.6 doesNotHaveEnsureDelete(longIndex, getArray().length(), false); 28.7 - setArray(getArray().ensure(longIndex)); 28.8 - setArray(getArray().set(index, value, false)); 28.9 + setArray(getArray().ensure(longIndex).set(index,value, false)); 28.10 } 28.11 28.12 private void checkIntegerKey(final String key) { 28.13 @@ -970,7 +969,7 @@ 28.14 final UserAccessorProperty uc = (UserAccessorProperty)oldProperty; 28.15 final int slot = uc.getSlot(); 28.16 28.17 - assert uc.getCurrentType() == Object.class; 28.18 + assert uc.getLocalType() == Object.class; 28.19 if (slot >= spillLength) { 28.20 uc.setAccessors(this, getMap(), new UserAccessorProperty.Accessors(getter, setter)); 28.21 } else { 28.22 @@ -1462,9 +1461,8 @@ 28.23 28.24 //invalidate any fast array setters 28.25 final ArrayData array = getArray(); 28.26 - if (array != null) { 28.27 - array.invalidateSetters(); 28.28 - } 28.29 + assert array != null; 28.30 + setArray(ArrayData.preventExtension(array)); 28.31 return this; 28.32 } 28.33 28.34 @@ -2645,20 +2643,22 @@ 28.35 * @param newLength new length to set 28.36 */ 28.37 public final void setLength(final long newLength) { 28.38 - final long arrayLength = getArray().length(); 28.39 - if (newLength == arrayLength) { 28.40 - return; 28.41 - } 28.42 - 28.43 - if (newLength > arrayLength) { 28.44 - setArray(getArray().ensure(newLength - 1)); 28.45 - if (getArray().canDelete(arrayLength, newLength - 1, false)) { 28.46 - setArray(getArray().delete(arrayLength, newLength - 1)); 28.47 - } 28.48 - return; 28.49 - } 28.50 - 28.51 - if (newLength < arrayLength) { 28.52 + ArrayData data = getArray(); 28.53 + final long arrayLength = data.length(); 28.54 + if (newLength == arrayLength) { 28.55 + return; 28.56 + } 28.57 + 28.58 + if (newLength > arrayLength) { 28.59 + data = data.ensure(newLength - 1); 28.60 + if (data.canDelete(arrayLength, newLength - 1, false)) { 28.61 + data = data.delete(arrayLength, newLength - 1); 28.62 + } 28.63 + setArray(data); 28.64 + return; 28.65 + } 28.66 + 28.67 + if (newLength < arrayLength) { 28.68 long actualLength = newLength; 28.69 28.70 // Check for numeric keys in property map and delete them or adjust length, depending on whether 28.71 @@ -2680,8 +2680,8 @@ 28.72 } 28.73 } 28.74 28.75 - setArray(getArray().shrink(actualLength)); 28.76 - getArray().setLength(actualLength); 28.77 + setArray(data.shrink(actualLength)); 28.78 + data.setLength(actualLength); 28.79 } 28.80 } 28.81 28.82 @@ -3194,8 +3194,9 @@ 28.83 final int index = getArrayIndex(primitiveKey); 28.84 28.85 if (isValidArrayIndex(index)) { 28.86 - if (getArray().has(index)) { 28.87 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.88 + final ArrayData data = getArray(); 28.89 + if (data.has(index)) { 28.90 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.91 } else { 28.92 doesNotHave(index, value, callSiteFlags); 28.93 } 28.94 @@ -3213,8 +3214,9 @@ 28.95 final int index = getArrayIndex(primitiveKey); 28.96 28.97 if (isValidArrayIndex(index)) { 28.98 - if (getArray().has(index)) { 28.99 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.100 + final ArrayData data = getArray(); 28.101 + if (data.has(index)) { 28.102 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.103 } else { 28.104 doesNotHave(index, value, callSiteFlags); 28.105 } 28.106 @@ -3232,8 +3234,9 @@ 28.107 final int index = getArrayIndex(primitiveKey); 28.108 28.109 if (isValidArrayIndex(index)) { 28.110 - if (getArray().has(index)) { 28.111 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.112 + final ArrayData data = getArray(); 28.113 + if (data.has(index)) { 28.114 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.115 } else { 28.116 doesNotHave(index, value, callSiteFlags); 28.117 } 28.118 @@ -3251,8 +3254,9 @@ 28.119 final int index = getArrayIndex(primitiveKey); 28.120 28.121 if (isValidArrayIndex(index)) { 28.122 - if (getArray().has(index)) { 28.123 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.124 + final ArrayData data = getArray(); 28.125 + if (data.has(index)) { 28.126 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.127 } else { 28.128 doesNotHave(index, value, callSiteFlags); 28.129 } 28.130 @@ -3269,8 +3273,9 @@ 28.131 final int index = getArrayIndex(key); 28.132 28.133 if (isValidArrayIndex(index)) { 28.134 - if (getArray().has(index)) { 28.135 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.136 + final ArrayData data = getArray(); 28.137 + if (data.has(index)) { 28.138 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.139 } else { 28.140 doesNotHave(index, value, callSiteFlags); 28.141 } 28.142 @@ -3287,8 +3292,9 @@ 28.143 final int index = getArrayIndex(key); 28.144 28.145 if (isValidArrayIndex(index)) { 28.146 - if (getArray().has(index)) { 28.147 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.148 + final ArrayData data = getArray(); 28.149 + if (data.has(index)) { 28.150 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.151 } else { 28.152 doesNotHave(index, value, callSiteFlags); 28.153 } 28.154 @@ -3305,8 +3311,9 @@ 28.155 final int index = getArrayIndex(key); 28.156 28.157 if (isValidArrayIndex(index)) { 28.158 - if (getArray().has(index)) { 28.159 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.160 + final ArrayData data = getArray(); 28.161 + if (data.has(index)) { 28.162 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.163 } else { 28.164 doesNotHave(index, value, callSiteFlags); 28.165 } 28.166 @@ -3323,8 +3330,9 @@ 28.167 final int index = getArrayIndex(key); 28.168 28.169 if (isValidArrayIndex(index)) { 28.170 - if (getArray().has(index)) { 28.171 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.172 + final ArrayData data = getArray(); 28.173 + if (data.has(index)) { 28.174 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.175 } else { 28.176 doesNotHave(index, value, callSiteFlags); 28.177 } 28.178 @@ -3341,8 +3349,9 @@ 28.179 final int index = getArrayIndex(key); 28.180 28.181 if (isValidArrayIndex(index)) { 28.182 - if (getArray().has(index)) { 28.183 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.184 + final ArrayData data = getArray(); 28.185 + if (data.has(index)) { 28.186 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.187 } else { 28.188 doesNotHave(index, value, callSiteFlags); 28.189 } 28.190 @@ -3359,8 +3368,9 @@ 28.191 final int index = getArrayIndex(key); 28.192 28.193 if (isValidArrayIndex(index)) { 28.194 - if (getArray().has(index)) { 28.195 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.196 + final ArrayData data = getArray(); 28.197 + if (data.has(index)) { 28.198 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.199 } else { 28.200 doesNotHave(index, value, callSiteFlags); 28.201 } 28.202 @@ -3377,8 +3387,9 @@ 28.203 final int index = getArrayIndex(key); 28.204 28.205 if (isValidArrayIndex(index)) { 28.206 - if (getArray().has(index)) { 28.207 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.208 + final ArrayData data = getArray(); 28.209 + if (data.has(index)) { 28.210 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.211 } else { 28.212 doesNotHave(index, value, callSiteFlags); 28.213 } 28.214 @@ -3395,8 +3406,9 @@ 28.215 final int index = getArrayIndex(key); 28.216 28.217 if (isValidArrayIndex(index)) { 28.218 - if (getArray().has(index)) { 28.219 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.220 + final ArrayData data = getArray(); 28.221 + if (data.has(index)) { 28.222 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.223 } else { 28.224 doesNotHave(index, value, callSiteFlags); 28.225 } 28.226 @@ -3413,7 +3425,8 @@ 28.227 final int index = getArrayIndex(key); 28.228 if (isValidArrayIndex(index)) { 28.229 if (getArray().has(index)) { 28.230 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.231 + final ArrayData data = getArray(); 28.232 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.233 } else { 28.234 doesNotHave(index, value, callSiteFlags); 28.235 } 28.236 @@ -3429,8 +3442,9 @@ 28.237 final int index = getArrayIndex(key); 28.238 28.239 if (isValidArrayIndex(index)) { 28.240 - if (getArray().has(index)) { 28.241 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.242 + final ArrayData data = getArray(); 28.243 + if (data.has(index)) { 28.244 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.245 } else { 28.246 doesNotHave(index, value, callSiteFlags); 28.247 } 28.248 @@ -3447,8 +3461,9 @@ 28.249 final int index = getArrayIndex(key); 28.250 28.251 if (isValidArrayIndex(index)) { 28.252 - if (getArray().has(index)) { 28.253 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.254 + final ArrayData data = getArray(); 28.255 + if (data.has(index)) { 28.256 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.257 } else { 28.258 doesNotHave(index, value, callSiteFlags); 28.259 } 28.260 @@ -3465,8 +3480,9 @@ 28.261 final int index = getArrayIndex(key); 28.262 28.263 if (isValidArrayIndex(index)) { 28.264 - if (getArray().has(index)) { 28.265 - setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.266 + final ArrayData data = getArray(); 28.267 + if (data.has(index)) { 28.268 + setArray(data.set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 28.269 } else { 28.270 doesNotHave(index, value, callSiteFlags); 28.271 }
29.1 --- a/src/jdk/nashorn/internal/runtime/SpillProperty.java Wed Oct 29 10:50:44 2014 -0700 29.2 +++ b/src/jdk/nashorn/internal/runtime/SpillProperty.java Fri Oct 31 20:17:42 2014 -0700 29.3 @@ -161,12 +161,12 @@ 29.4 */ 29.5 public SpillProperty(final String key, final int flags, final int slot) { 29.6 super(key, flags, slot, primitiveGetter(slot), primitiveSetter(slot), objectGetter(slot), objectSetter(slot)); 29.7 - assert !OBJECT_FIELDS_ONLY || getCurrentType() == Object.class; 29.8 + assert !OBJECT_FIELDS_ONLY || getLocalType() == Object.class; 29.9 } 29.10 29.11 SpillProperty(final String key, final int flags, final int slot, final Class<?> initialType) { 29.12 this(key, flags, slot); 29.13 - setCurrentType(OBJECT_FIELDS_ONLY ? Object.class : initialType); 29.14 + setType(OBJECT_FIELDS_ONLY ? Object.class : initialType); 29.15 } 29.16 29.17 SpillProperty(final String key, final int flags, final int slot, final ScriptObject owner, final Object initialValue) {
30.1 --- a/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Wed Oct 29 10:50:44 2014 -0700 30.2 +++ b/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Fri Oct 31 20:17:42 2014 -0700 30.3 @@ -27,16 +27,16 @@ 30.4 30.5 import static jdk.nashorn.internal.lookup.Lookup.MH; 30.6 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 30.7 -import static jdk.nashorn.internal.runtime.JSType.CONVERT_OBJECT_OPTIMISTIC; 30.8 -import static jdk.nashorn.internal.runtime.JSType.getAccessorTypeIndex; 30.9 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 30.10 +import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT; 30.11 +import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROGRAM_POINT_SHIFT; 30.12 30.13 import java.lang.invoke.MethodHandle; 30.14 import java.lang.invoke.MethodHandles; 30.15 import java.lang.invoke.MethodType; 30.16 -import java.util.concurrent.Callable; 30.17 import jdk.nashorn.internal.lookup.Lookup; 30.18 import jdk.nashorn.internal.runtime.linker.Bootstrap; 30.19 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 30.20 30.21 /** 30.22 * Property with user defined getters/setters. Actual getter and setter 30.23 @@ -69,38 +69,29 @@ 30.24 private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); 30.25 30.26 /** Getter method handle */ 30.27 - private final static MethodHandle INVOKE_GETTER_ACCESSOR = findOwnMH_S("invokeGetterAccessor", Object.class, Accessors.class, Object.class); 30.28 + private final static MethodHandle INVOKE_OBJECT_GETTER = findOwnMH_S("invokeObjectGetter", Object.class, Accessors.class, MethodHandle.class, Object.class); 30.29 + private final static MethodHandle INVOKE_INT_GETTER = findOwnMH_S("invokeIntGetter", int.class, Accessors.class, MethodHandle.class, int.class, Object.class); 30.30 + private final static MethodHandle INVOKE_LONG_GETTER = findOwnMH_S("invokeLongGetter", long.class, Accessors.class, MethodHandle.class, int.class, Object.class); 30.31 + private final static MethodHandle INVOKE_NUMBER_GETTER = findOwnMH_S("invokeNumberGetter", double.class, Accessors.class, MethodHandle.class, int.class, Object.class); 30.32 30.33 /** Setter method handle */ 30.34 - private final static MethodHandle INVOKE_SETTER_ACCESSOR = findOwnMH_S("invokeSetterAccessor", void.class, Accessors.class, String.class, Object.class, Object.class); 30.35 + private final static MethodHandle INVOKE_OBJECT_SETTER = findOwnMH_S("invokeObjectSetter", void.class, Accessors.class, MethodHandle.class, String.class, Object.class, Object.class); 30.36 + private final static MethodHandle INVOKE_INT_SETTER = findOwnMH_S("invokeIntSetter", void.class, Accessors.class, MethodHandle.class, String.class, Object.class, int.class); 30.37 + private final static MethodHandle INVOKE_LONG_SETTER = findOwnMH_S("invokeLongSetter", void.class, Accessors.class, MethodHandle.class, String.class, Object.class, long.class); 30.38 + private final static MethodHandle INVOKE_NUMBER_SETTER = findOwnMH_S("invokeNumberSetter", void.class, Accessors.class, MethodHandle.class, String.class, Object.class, double.class); 30.39 30.40 - /** Dynamic invoker for getter */ 30.41 - private static final Object GETTER_INVOKER_KEY = new Object(); 30.42 30.43 - private static MethodHandle getINVOKE_UA_GETTER() { 30.44 - 30.45 - return Context.getGlobal().getDynamicInvoker(GETTER_INVOKER_KEY, 30.46 - new Callable<MethodHandle>() { 30.47 - @Override 30.48 - public MethodHandle call() { 30.49 - return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 30.50 - Object.class, Object.class); 30.51 - } 30.52 - }); 30.53 + static MethodHandle getINVOKE_UA_GETTER(final Class<?> returnType, final int programPoint) { 30.54 + if (UnwarrantedOptimismException.isValid(programPoint)) { 30.55 + final int flags = NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC | programPoint << CALLSITE_PROGRAM_POINT_SHIFT; 30.56 + return Bootstrap.createDynamicInvoker("dyn:call", flags, returnType, Object.class, Object.class); 30.57 + } else { 30.58 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, Object.class, Object.class); 30.59 + } 30.60 } 30.61 30.62 - /** Dynamic invoker for setter */ 30.63 - private static Object SETTER_INVOKER_KEY = new Object(); 30.64 - 30.65 - private static MethodHandle getINVOKE_UA_SETTER() { 30.66 - return Context.getGlobal().getDynamicInvoker(SETTER_INVOKER_KEY, 30.67 - new Callable<MethodHandle>() { 30.68 - @Override 30.69 - public MethodHandle call() { 30.70 - return Bootstrap.createDynamicInvoker("dyn:call", void.class, 30.71 - Object.class, Object.class, Object.class); 30.72 - } 30.73 - }); 30.74 + static MethodHandle getINVOKE_UA_SETTER(final Class<?> valueType) { 30.75 + return Bootstrap.createDynamicInvoker("dyn:call", void.class, Object.class, Object.class, valueType); 30.76 } 30.77 30.78 /** 30.79 @@ -158,7 +149,7 @@ 30.80 } 30.81 30.82 @Override 30.83 - public Class<?> getCurrentType() { 30.84 + protected Class<?> getLocalType() { 30.85 return Object.class; 30.86 } 30.87 30.88 @@ -189,7 +180,13 @@ 30.89 30.90 @Override 30.91 public Object getObjectValue(final ScriptObject self, final ScriptObject owner) { 30.92 - return invokeGetterAccessor(getAccessors((owner != null) ? owner : self), self); 30.93 + try { 30.94 + return invokeObjectGetter(getAccessors((owner != null) ? owner : self), getINVOKE_UA_GETTER(Object.class, INVALID_PROGRAM_POINT), self); 30.95 + } catch (final Error | RuntimeException t) { 30.96 + throw t; 30.97 + } catch (final Throwable t) { 30.98 + throw new RuntimeException(t); 30.99 + } 30.100 } 30.101 30.102 @Override 30.103 @@ -209,41 +206,33 @@ 30.104 30.105 @Override 30.106 public void setValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict) { 30.107 - invokeSetterAccessor(getAccessors((owner != null) ? owner : self), strict ? getKey() : null, self, value); 30.108 + try { 30.109 + invokeObjectSetter(getAccessors((owner != null) ? owner : self), getINVOKE_UA_SETTER(Object.class), strict ? getKey() : null, self, value); 30.110 + } catch (final Error | RuntimeException t) { 30.111 + throw t; 30.112 + } catch (final Throwable t) { 30.113 + throw new RuntimeException(t); 30.114 + } 30.115 } 30.116 30.117 @Override 30.118 public MethodHandle getGetter(final Class<?> type) { 30.119 //this returns a getter on the format (Accessors, Object receiver) 30.120 - return Lookup.filterReturnType(INVOKE_GETTER_ACCESSOR, type); 30.121 + return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type); 30.122 } 30.123 30.124 @Override 30.125 public MethodHandle getOptimisticGetter(final Class<?> type, final int programPoint) { 30.126 - //fortype is always object, but in the optimistic world we have to throw 30.127 - //unwarranted optimism exception for narrower types. We can improve this 30.128 - //by checking for boxed types and unboxing them, but it is doubtful that 30.129 - //this gives us any performance, as UserAccessorProperties are typically not 30.130 - //primitives. Are there? TODO: investigate later. For now we just throw an 30.131 - //exception for narrower types than object 30.132 - 30.133 - if (type.isPrimitive()) { 30.134 - final MethodHandle getter = getGetter(Object.class); 30.135 - final MethodHandle mh = 30.136 - MH.asType( 30.137 - MH.filterReturnValue( 30.138 - getter, 30.139 - MH.insertArguments( 30.140 - CONVERT_OBJECT_OPTIMISTIC.get(getAccessorTypeIndex(type)), 30.141 - 1, 30.142 - programPoint)), 30.143 - getter.type().changeReturnType(type)); 30.144 - 30.145 - return mh; 30.146 + if (type == int.class) { 30.147 + return INVOKE_INT_GETTER; 30.148 + } else if (type == long.class) { 30.149 + return INVOKE_LONG_GETTER; 30.150 + } else if (type == double.class) { 30.151 + return INVOKE_NUMBER_GETTER; 30.152 + } else { 30.153 + assert type == Object.class; 30.154 + return INVOKE_OBJECT_GETTER; 30.155 } 30.156 - 30.157 - assert type == Object.class; 30.158 - return getGetter(type); 30.159 } 30.160 30.161 @Override 30.162 @@ -259,7 +248,16 @@ 30.163 30.164 @Override 30.165 public MethodHandle getSetter(final Class<?> type, final PropertyMap currentMap) { 30.166 - return INVOKE_SETTER_ACCESSOR; 30.167 + if (type == int.class) { 30.168 + return INVOKE_INT_SETTER; 30.169 + } else if (type == long.class) { 30.170 + return INVOKE_LONG_SETTER; 30.171 + } else if (type == double.class) { 30.172 + return INVOKE_NUMBER_SETTER; 30.173 + } else { 30.174 + assert type == Object.class; 30.175 + return INVOKE_OBJECT_SETTER; 30.176 + } 30.177 } 30.178 30.179 @Override 30.180 @@ -282,31 +280,81 @@ 30.181 // getter/setter may be inherited. If so, proto is bound during lookup. In either 30.182 // inherited or self case, slot is also bound during lookup. Actual ScriptFunction 30.183 // to be called is retrieved everytime and applied. 30.184 - private static Object invokeGetterAccessor(final Accessors gs, final Object self) { 30.185 + @SuppressWarnings("unused") 30.186 + private static Object invokeObjectGetter(final Accessors gs, final MethodHandle invoker, final Object self) throws Throwable { 30.187 final Object func = gs.getter; 30.188 if (func instanceof ScriptFunction) { 30.189 - try { 30.190 - return getINVOKE_UA_GETTER().invokeExact(func, self); 30.191 - } catch (final Error | RuntimeException t) { 30.192 - throw t; 30.193 - } catch (final Throwable t) { 30.194 - throw new RuntimeException(t); 30.195 - } 30.196 + return invoker.invokeExact(func, self); 30.197 } 30.198 30.199 return UNDEFINED; 30.200 } 30.201 30.202 - private static void invokeSetterAccessor(final Accessors gs, final String name, final Object self, final Object value) { 30.203 + @SuppressWarnings("unused") 30.204 + private static int invokeIntGetter(final Accessors gs, final MethodHandle invoker, final int programPoint, final Object self) throws Throwable { 30.205 + final Object func = gs.getter; 30.206 + if (func instanceof ScriptFunction) { 30.207 + return (int) invoker.invokeExact(func, self); 30.208 + } 30.209 + 30.210 + throw new UnwarrantedOptimismException(UNDEFINED, programPoint); 30.211 + } 30.212 + 30.213 + @SuppressWarnings("unused") 30.214 + private static long invokeLongGetter(final Accessors gs, final MethodHandle invoker, final int programPoint, final Object self) throws Throwable { 30.215 + final Object func = gs.getter; 30.216 + if (func instanceof ScriptFunction) { 30.217 + return (long) invoker.invokeExact(func, self); 30.218 + } 30.219 + 30.220 + throw new UnwarrantedOptimismException(UNDEFINED, programPoint); 30.221 + } 30.222 + 30.223 + @SuppressWarnings("unused") 30.224 + private static double invokeNumberGetter(final Accessors gs, final MethodHandle invoker, final int programPoint, final Object self) throws Throwable { 30.225 + final Object func = gs.getter; 30.226 + if (func instanceof ScriptFunction) { 30.227 + return (double) invoker.invokeExact(func, self); 30.228 + } 30.229 + 30.230 + throw new UnwarrantedOptimismException(UNDEFINED, programPoint); 30.231 + } 30.232 + 30.233 + @SuppressWarnings("unused") 30.234 + private static void invokeObjectSetter(final Accessors gs, final MethodHandle invoker, final String name, final Object self, final Object value) throws Throwable { 30.235 final Object func = gs.setter; 30.236 if (func instanceof ScriptFunction) { 30.237 - try { 30.238 - getINVOKE_UA_SETTER().invokeExact(func, self, value); 30.239 - } catch (final Error | RuntimeException t) { 30.240 - throw t; 30.241 - } catch (final Throwable t) { 30.242 - throw new RuntimeException(t); 30.243 - } 30.244 + invoker.invokeExact(func, self, value); 30.245 + } else if (name != null) { 30.246 + throw typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self)); 30.247 + } 30.248 + } 30.249 + 30.250 + @SuppressWarnings("unused") 30.251 + private static void invokeIntSetter(final Accessors gs, final MethodHandle invoker, final String name, final Object self, final int value) throws Throwable { 30.252 + final Object func = gs.setter; 30.253 + if (func instanceof ScriptFunction) { 30.254 + invoker.invokeExact(func, self, value); 30.255 + } else if (name != null) { 30.256 + throw typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self)); 30.257 + } 30.258 + } 30.259 + 30.260 + @SuppressWarnings("unused") 30.261 + private static void invokeLongSetter(final Accessors gs, final MethodHandle invoker, final String name, final Object self, final long value) throws Throwable { 30.262 + final Object func = gs.setter; 30.263 + if (func instanceof ScriptFunction) { 30.264 + invoker.invokeExact(func, self, value); 30.265 + } else if (name != null) { 30.266 + throw typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self)); 30.267 + } 30.268 + } 30.269 + 30.270 + @SuppressWarnings("unused") 30.271 + private static void invokeNumberSetter(final Accessors gs, final MethodHandle invoker, final String name, final Object self, final double value) throws Throwable { 30.272 + final Object func = gs.setter; 30.273 + if (func instanceof ScriptFunction) { 30.274 + invoker.invokeExact(func, self, value); 30.275 } else if (name != null) { 30.276 throw typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self)); 30.277 }
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/AnyElements.java Fri Oct 31 20:17:42 2014 -0700 31.3 @@ -0,0 +1,38 @@ 31.4 +/* 31.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 + * 31.8 + * This code is free software; you can redistribute it and/or modify it 31.9 + * under the terms of the GNU General Public License version 2 only, as 31.10 + * published by the Free Software Foundation. Oracle designates this 31.11 + * particular file as subject to the "Classpath" exception as provided 31.12 + * by Oracle in the LICENSE file that accompanied this code. 31.13 + * 31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.17 + * version 2 for more details (a copy is included in the LICENSE file that 31.18 + * accompanied this code). 31.19 + * 31.20 + * You should have received a copy of the GNU General Public License version 31.21 + * 2 along with this work; if not, write to the Free Software Foundation, 31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.23 + * 31.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 31.25 + * or visit www.oracle.com if you need additional information or have any 31.26 + * questions. 31.27 + */ 31.28 +package jdk.nashorn.internal.runtime.arrays; 31.29 + 31.30 +/** 31.31 + * Marker interface for any ContinuousArray with any elements 31.32 + * Used for type checks that throw ClassCastExceptions and force relinks 31.33 + * for fast NativeArray specializations of builtin methods 31.34 + */ 31.35 +public interface AnyElements { 31.36 + /** 31.37 + * Return a numeric weight of the element type - wider is higher 31.38 + * @return element type weight 31.39 + */ 31.40 + public int getElementWeight(); 31.41 +} 31.42 \ No newline at end of file
32.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Wed Oct 29 10:50:44 2014 -0700 32.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Fri Oct 31 20:17:42 2014 -0700 32.3 @@ -28,6 +28,7 @@ 32.4 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; 32.5 import java.lang.invoke.MethodHandle; 32.6 import java.lang.invoke.MethodHandles; 32.7 +import java.lang.reflect.Array; 32.8 import java.nio.ByteBuffer; 32.9 import jdk.internal.dynalink.CallSiteDescriptor; 32.10 import jdk.internal.dynalink.linker.GuardedInvocation; 32.11 @@ -37,6 +38,7 @@ 32.12 import jdk.nashorn.internal.objects.Global; 32.13 import jdk.nashorn.internal.runtime.JSType; 32.14 import jdk.nashorn.internal.runtime.PropertyDescriptor; 32.15 +import jdk.nashorn.internal.runtime.ScriptRuntime; 32.16 import jdk.nashorn.internal.runtime.UnwarrantedOptimismException; 32.17 32.18 /** 32.19 @@ -49,10 +51,180 @@ 32.20 /** Mask for getting a chunk */ 32.21 protected static final int CHUNK_MASK = CHUNK_SIZE - 1; 32.22 32.23 + /** Untouched data - still link callsites as IntArrayData, but expands to 32.24 + * a proper ArrayData when we try to write to it */ 32.25 + public static final ArrayData EMPTY_ARRAY = new UntouchedArrayData(); 32.26 + 32.27 /** 32.28 * Immutable empty array to get ScriptObjects started. 32.29 + * Use the same array and convert it to mutable as soon as it is modified 32.30 */ 32.31 - public static final ArrayData EMPTY_ARRAY = new NoTypeArrayData(); 32.32 + private static class UntouchedArrayData extends ContinuousArrayData { 32.33 + private UntouchedArrayData() { 32.34 + this(0); 32.35 + } 32.36 + 32.37 + private UntouchedArrayData(final int length) { 32.38 + super(length); 32.39 + } 32.40 + 32.41 + private ArrayData toRealArrayData() { 32.42 + return toRealArrayData(0); 32.43 + } 32.44 + 32.45 + private ArrayData toRealArrayData(final int index) { 32.46 + final IntArrayData newData = new IntArrayData(index + 1); 32.47 + if (index == 0) { 32.48 + return newData; 32.49 + } 32.50 + return new DeletedRangeArrayFilter(newData, 0, index); 32.51 + } 32.52 + 32.53 + @Override 32.54 + public ContinuousArrayData copy() { 32.55 + return new UntouchedArrayData((int)length); 32.56 + } 32.57 + 32.58 + @Override 32.59 + public Object asArrayOfType(final Class<?> componentType) { 32.60 + return Array.newInstance(componentType, 0); 32.61 + } 32.62 + 32.63 + @Override 32.64 + public Object[] asObjectArray() { 32.65 + return ScriptRuntime.EMPTY_ARRAY; 32.66 + } 32.67 + 32.68 + @Override 32.69 + public ArrayData ensure(final long safeIndex) { 32.70 + if (safeIndex > 0L) { 32.71 + return toRealArrayData((int)safeIndex).ensure(safeIndex); 32.72 + } 32.73 + return this; 32.74 + } 32.75 + 32.76 + @Override 32.77 + public ArrayData convert(final Class<?> type) { 32.78 + return toRealArrayData(0).convert(type); 32.79 + } 32.80 + 32.81 + @Override 32.82 + public void shiftLeft(final int by) { 32.83 + //nop, always empty or we wouldn't be of this class 32.84 + } 32.85 + 32.86 + @Override 32.87 + public ArrayData shiftRight(final int by) { 32.88 + return this; //always empty or we wouldn't be of this class 32.89 + } 32.90 + 32.91 + @Override 32.92 + public ArrayData shrink(final long newLength) { 32.93 + return this; 32.94 + } 32.95 + 32.96 + @Override 32.97 + public ArrayData set(final int index, final Object value, final boolean strict) { 32.98 + return toRealArrayData(index).set(index, value, strict); 32.99 + } 32.100 + 32.101 + @Override 32.102 + public ArrayData set(final int index, final int value, final boolean strict) { 32.103 + return toRealArrayData(index).set(index, value, strict); 32.104 + } 32.105 + 32.106 + @Override 32.107 + public ArrayData set(final int index, final long value, final boolean strict) { 32.108 + return toRealArrayData(index).set(index, value, strict); 32.109 + } 32.110 + 32.111 + @Override 32.112 + public ArrayData set(final int index, final double value, final boolean strict) { 32.113 + return toRealArrayData(index).set(index, value, strict); 32.114 + } 32.115 + 32.116 + @Override 32.117 + public int getInt(final int index) { 32.118 + throw new ArrayIndexOutOfBoundsException(index); //empty 32.119 + } 32.120 + 32.121 + @Override 32.122 + public long getLong(final int index) { 32.123 + throw new ArrayIndexOutOfBoundsException(index); //empty 32.124 + } 32.125 + 32.126 + @Override 32.127 + public double getDouble(final int index) { 32.128 + throw new ArrayIndexOutOfBoundsException(index); //empty 32.129 + } 32.130 + 32.131 + @Override 32.132 + public Object getObject(final int index) { 32.133 + throw new ArrayIndexOutOfBoundsException(index); //empty 32.134 + } 32.135 + 32.136 + @Override 32.137 + public boolean has(final int index) { 32.138 + return false; //empty 32.139 + } 32.140 + 32.141 + @Override 32.142 + public ArrayData delete(final int index) { 32.143 + return new DeletedRangeArrayFilter(this, index, index); 32.144 + } 32.145 + 32.146 + @Override 32.147 + public ArrayData delete(final long fromIndex, final long toIndex) { 32.148 + return new DeletedRangeArrayFilter(this, fromIndex, toIndex); 32.149 + } 32.150 + 32.151 + @Override 32.152 + public Object pop() { 32.153 + return ScriptRuntime.UNDEFINED; 32.154 + } 32.155 + 32.156 + @Override 32.157 + public ArrayData push(final boolean strict, final Object item) { 32.158 + return toRealArrayData().push(strict, item); 32.159 + } 32.160 + 32.161 + @Override 32.162 + public ArrayData slice(final long from, final long to) { 32.163 + return this; //empty 32.164 + } 32.165 + 32.166 + @Override 32.167 + public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) { 32.168 + return otherData.copy(); 32.169 + } 32.170 + 32.171 + //no need to override fastPopInt, as the default behavior is to throw classcast exception so we 32.172 + //can relink and return an undefined, this is the IntArrayData default behavior 32.173 + @Override 32.174 + public String toString() { 32.175 + return getClass().getSimpleName(); 32.176 + } 32.177 + 32.178 + @Override 32.179 + public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) { 32.180 + return null; 32.181 + } 32.182 + 32.183 + @Override 32.184 + public MethodHandle getElementSetter(final Class<?> elementType) { 32.185 + return null; 32.186 + } 32.187 + 32.188 + @Override 32.189 + public Class<?> getElementType() { 32.190 + return int.class; 32.191 + } 32.192 + 32.193 + @Override 32.194 + public Class<?> getBoxedElementType() { 32.195 + return Integer.class; 32.196 + } 32.197 + }; 32.198 32.199 /** 32.200 * Length of the array data. Not necessarily length of the wrapped array. 32.201 @@ -77,7 +249,7 @@ 32.202 * Factory method for unspecified array - start as int 32.203 * @return ArrayData 32.204 */ 32.205 - public static ArrayData initialArray() { 32.206 + public final static ArrayData initialArray() { 32.207 return new IntArrayData(); 32.208 } 32.209 32.210 @@ -92,33 +264,22 @@ 32.211 throw new UnwarrantedOptimismException(data.getObject(index), programPoint); 32.212 } 32.213 32.214 - private static int alignUp(final int size) { 32.215 + /** 32.216 + * Align an array size up to the nearest array chunk size 32.217 + * @param size size required 32.218 + * @return size given, always >= size 32.219 + */ 32.220 + protected final static int alignUp(final int size) { 32.221 return size + CHUNK_SIZE - 1 & ~(CHUNK_SIZE - 1); 32.222 } 32.223 32.224 /** 32.225 - * Generic invalidation hook for script object to have call sites to this array indexing 32.226 - * relinked, e.g. when a native array is marked as non extensible 32.227 - */ 32.228 - public void invalidateGetters() { 32.229 - //subclass responsibility 32.230 - } 32.231 - 32.232 - /** 32.233 - * Generic invalidation hook for script object to have call sites to this array indexing 32.234 - * relinked, e.g. when a native array is marked as non extensible 32.235 - */ 32.236 - public void invalidateSetters() { 32.237 - //subclass responsibility 32.238 - } 32.239 - 32.240 - /** 32.241 * Factory method for unspecified array with given length - start as int array data 32.242 * 32.243 * @param length the initial length 32.244 * @return ArrayData 32.245 */ 32.246 - public static ArrayData allocate(final int length) { 32.247 + public static final ArrayData allocate(final int length) { 32.248 if (length == 0) { 32.249 return new IntArrayData(); 32.250 } else if (length >= SparseArrayData.MAX_DENSE_LENGTH) { 32.251 @@ -134,7 +295,7 @@ 32.252 * @param array the array 32.253 * @return ArrayData wrapping this array 32.254 */ 32.255 - public static ArrayData allocate(final Object array) { 32.256 + public static final ArrayData allocate(final Object array) { 32.257 final Class<?> clazz = array.getClass(); 32.258 32.259 if (clazz == int[].class) { 32.260 @@ -154,7 +315,7 @@ 32.261 * @param array the array to use for initial elements 32.262 * @return the ArrayData 32.263 */ 32.264 - public static ArrayData allocate(final int[] array) { 32.265 + public static final ArrayData allocate(final int[] array) { 32.266 return new IntArrayData(array, array.length); 32.267 } 32.268 32.269 @@ -164,7 +325,7 @@ 32.270 * @param array the array to use for initial elements 32.271 * @return the ArrayData 32.272 */ 32.273 - public static ArrayData allocate(final long[] array) { 32.274 + public static final ArrayData allocate(final long[] array) { 32.275 return new LongArrayData(array, array.length); 32.276 } 32.277 32.278 @@ -174,7 +335,7 @@ 32.279 * @param array the array to use for initial elements 32.280 * @return the ArrayData 32.281 */ 32.282 - public static ArrayData allocate(final double[] array) { 32.283 + public static final ArrayData allocate(final double[] array) { 32.284 return new NumberArrayData(array, array.length); 32.285 } 32.286 32.287 @@ -184,7 +345,7 @@ 32.288 * @param array the array to use for initial elements 32.289 * @return the ArrayData 32.290 */ 32.291 - public static ArrayData allocate(final Object[] array) { 32.292 + public static final ArrayData allocate(final Object[] array) { 32.293 return new ObjectArrayData(array, array.length); 32.294 } 32.295 32.296 @@ -194,7 +355,7 @@ 32.297 * @param buf the nio ByteBuffer to wrap 32.298 * @return the ArrayData 32.299 */ 32.300 - public static ArrayData allocate(final ByteBuffer buf) { 32.301 + public static final ArrayData allocate(final ByteBuffer buf) { 32.302 return new ByteBufferArrayData(buf); 32.303 } 32.304 32.305 @@ -204,7 +365,7 @@ 32.306 * @param underlying the underlying ArrayData to wrap in the freeze filter 32.307 * @return the frozen ArrayData 32.308 */ 32.309 - public static ArrayData freeze(final ArrayData underlying) { 32.310 + public static final ArrayData freeze(final ArrayData underlying) { 32.311 return new FrozenArrayFilter(underlying); 32.312 } 32.313 32.314 @@ -214,11 +375,21 @@ 32.315 * @param underlying the underlying ArrayData to wrap in the seal filter 32.316 * @return the sealed ArrayData 32.317 */ 32.318 - public static ArrayData seal(final ArrayData underlying) { 32.319 + public static final ArrayData seal(final ArrayData underlying) { 32.320 return new SealedArrayFilter(underlying); 32.321 } 32.322 32.323 /** 32.324 + * Prevent this array from being extended 32.325 + * 32.326 + * @param underlying the underlying ArrayData to wrap in the non extensible filter 32.327 + * @return new array data, filtered 32.328 + */ 32.329 + public static final ArrayData preventExtension(final ArrayData underlying) { 32.330 + return new NonExtensibleArrayFilter(underlying); 32.331 + } 32.332 + 32.333 + /** 32.334 * Return the length of the array data. This may differ from the actual 32.335 * length of the array this wraps as length may be set or gotten as any 32.336 * other JavaScript Property 32.337 @@ -728,5 +899,4 @@ 32.338 public GuardedInvocation findFastSetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { // array, index, value 32.339 return null; 32.340 } 32.341 - 32.342 }
33.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayIndex.java Wed Oct 29 10:50:44 2014 -0700 33.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayIndex.java Fri Oct 31 20:17:42 2014 -0700 33.3 @@ -182,15 +182,15 @@ 33.4 } 33.5 33.6 /** 33.7 - * Convert an index to a long value. This basically amounts to ANDing it 33.8 - * with {@link JSType#MAX_UINT}, as the maximum array index in JavaScript 33.9 + * Convert an index to a long value. This basically amounts to converting it into a 33.10 + * {@link JSType#toUint32(int)} uint32} as the maximum array index in JavaScript 33.11 * is 0xfffffffe 33.12 * 33.13 * @param index index to convert to long form 33.14 * @return index as uint32 in a long 33.15 */ 33.16 public static long toLongIndex(final int index) { 33.17 - return index & JSType.MAX_UINT; 33.18 + return JSType.toUint32(index); 33.19 } 33.20 33.21 /** 33.22 @@ -201,7 +201,7 @@ 33.23 * @return index as string 33.24 */ 33.25 public static String toKey(final int index) { 33.26 - return Long.toString(index & JSType.MAX_UINT); 33.27 + return Long.toString(JSType.toUint32(index)); 33.28 } 33.29 33.30 }
34.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ContinuousArrayData.java Wed Oct 29 10:50:44 2014 -0700 34.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ContinuousArrayData.java Fri Oct 31 20:17:42 2014 -0700 34.3 @@ -1,5 +1,4 @@ 34.4 /* 34.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 34.6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 * 34.8 * This code is free software; you can redistribute it and/or modify it 34.9 @@ -30,7 +29,6 @@ 34.10 import static jdk.nashorn.internal.runtime.JSType.getAccessorTypeIndex; 34.11 import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT; 34.12 import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid; 34.13 - 34.14 import java.lang.invoke.MethodHandle; 34.15 import java.lang.invoke.MethodHandles; 34.16 import java.lang.invoke.MethodType; 34.17 @@ -50,9 +48,6 @@ 34.18 */ 34.19 @Logger(name="arrays") 34.20 public abstract class ContinuousArrayData extends ArrayData { 34.21 - 34.22 - private SwitchPoint sp; 34.23 - 34.24 /** 34.25 * Constructor 34.26 * @param length length (elementLength) 34.27 @@ -61,18 +56,6 @@ 34.28 super(length); 34.29 } 34.30 34.31 - private SwitchPoint ensureSwitchPointExists() { 34.32 - if (sp == null){ 34.33 - sp = new SwitchPoint(); 34.34 - } 34.35 - return sp; 34.36 - } 34.37 - 34.38 - @Override 34.39 - public void invalidateSetters() { 34.40 - SwitchPoint.invalidateAll(new SwitchPoint[] { ensureSwitchPointExists() }); 34.41 - } 34.42 - 34.43 /** 34.44 * Check if we can put one more element at the end of this continous 34.45 * array without reallocating, or if we are overwriting an already 34.46 @@ -86,6 +69,14 @@ 34.47 } 34.48 34.49 /** 34.50 + * Check if an arraydata is empty 34.51 + * @return true if empty 34.52 + */ 34.53 + public boolean isEmpty() { 34.54 + return length == 0L; 34.55 + } 34.56 + 34.57 + /** 34.58 * Return element getter for a certain type at a certain program point 34.59 * @param returnType return type 34.60 * @param programPoint program point 34.61 @@ -109,13 +100,16 @@ 34.62 * @param index index to check - currently only int indexes 34.63 * @return index 34.64 */ 34.65 - protected int throwHas(final int index) { 34.66 + protected final int throwHas(final int index) { 34.67 if (!has(index)) { 34.68 throw new ClassCastException(); 34.69 } 34.70 return index; 34.71 } 34.72 34.73 + @Override 34.74 + public abstract ContinuousArrayData copy(); 34.75 + 34.76 /** 34.77 * Returns the type used to store an element in this array 34.78 * @return element type 34.79 @@ -128,6 +122,25 @@ 34.80 } 34.81 34.82 /** 34.83 + * Returns the boxed type of the type used to store an element in this array 34.84 + * @return element type 34.85 + */ 34.86 + public abstract Class<?> getBoxedElementType(); 34.87 + 34.88 + /** 34.89 + * Get the widest element type of two arrays. This can be done faster in subclasses, but 34.90 + * this works for all ContinuousArrayDatas and for where more optimal checks haven't been 34.91 + * implemented. 34.92 + * 34.93 + * @param otherData another ContinuousArrayData 34.94 + * @return the widest boxed element type 34.95 + */ 34.96 + public ContinuousArrayData widest(final ContinuousArrayData otherData) { 34.97 + final Class<?> elementType = getElementType(); 34.98 + return Type.widest(elementType, otherData.getElementType()) == elementType ? this : otherData; 34.99 + } 34.100 + 34.101 + /** 34.102 * Look up a continuous array element getter 34.103 * @param get getter, sometimes combined with a has check that throws CCE on failure for relink 34.104 * @param returnType return type 34.105 @@ -256,12 +269,7 @@ 34.106 final Object[] args = request.getArguments(); 34.107 final int index = (int)args[args.length - 2]; 34.108 34.109 - //sp may be invalidated by e.g. preventExtensions before the first setter is linked 34.110 - //then it is already created. otherwise, create it here to guard against future 34.111 - //invalidations 34.112 - ensureSwitchPointExists(); 34.113 - 34.114 - if (!sp.hasBeenInvalidated() && hasRoomFor(index)) { 34.115 + if (hasRoomFor(index)) { 34.116 MethodHandle setElement = getElementSetter(elementType); //Z(continuousarraydata, int, int), return true if successful 34.117 if (setElement != null) { 34.118 //else we are dealing with a wider type than supported by this callsite 34.119 @@ -269,7 +277,7 @@ 34.120 getArray = MH.asType(getArray, getArray.type().changeReturnType(getClass())); 34.121 setElement = MH.filterArguments(setElement, 0, getArray); 34.122 final MethodHandle guard = MH.insertArguments(FAST_ACCESS_GUARD, 0, clazz); 34.123 - return new GuardedInvocation(setElement, guard, sp, ClassCastException.class); //CCE if not a scriptObject anymore 34.124 + return new GuardedInvocation(setElement, guard, (SwitchPoint)null, ClassCastException.class); //CCE if not a scriptObject anymore 34.125 } 34.126 } 34.127 } 34.128 @@ -344,4 +352,13 @@ 34.129 public Object fastPopObject() { 34.130 throw new ClassCastException(String.valueOf(getClass())); //type is wrong, relink 34.131 } 34.132 + 34.133 + /** 34.134 + * Specialization - fast concat implementation 34.135 + * @param otherData data to concat 34.136 + * @return new arraydata 34.137 + */ 34.138 + public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) { 34.139 + throw new ClassCastException(String.valueOf(getClass()) + " != " + String.valueOf(otherData.getClass())); 34.140 + } 34.141 }
35.1 --- a/src/jdk/nashorn/internal/runtime/arrays/IntArrayData.java Wed Oct 29 10:50:44 2014 -0700 35.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/IntArrayData.java Fri Oct 31 20:17:42 2014 -0700 35.3 @@ -26,7 +26,6 @@ 35.4 package jdk.nashorn.internal.runtime.arrays; 35.5 35.6 import static jdk.nashorn.internal.codegen.CompilerConstants.specialCall; 35.7 - 35.8 import java.lang.invoke.MethodHandle; 35.9 import java.lang.invoke.MethodHandles; 35.10 import java.util.Arrays; 35.11 @@ -57,17 +56,32 @@ 35.12 * @param array an int array 35.13 * @param length a length, not necessarily array.length 35.14 */ 35.15 - IntArrayData(final int array[], final int length) { 35.16 + IntArrayData(final int[] array, final int length) { 35.17 super(length); 35.18 - assert array.length >= length; 35.19 + assert array == null || array.length >= length; 35.20 this.array = array; 35.21 } 35.22 35.23 @Override 35.24 - public Class<?> getElementType() { 35.25 + public final Class<?> getElementType() { 35.26 return int.class; 35.27 } 35.28 35.29 + @Override 35.30 + public final Class<?> getBoxedElementType() { 35.31 + return Integer.class; 35.32 + } 35.33 + 35.34 + @Override 35.35 + public final int getElementWeight() { 35.36 + return 1; 35.37 + } 35.38 + 35.39 + @Override 35.40 + public final ContinuousArrayData widest(final ContinuousArrayData otherData) { 35.41 + return otherData; 35.42 + } 35.43 + 35.44 private static final MethodHandle HAS_GET_ELEM = specialCall(MethodHandles.lookup(), IntArrayData.class, "getElem", int.class, int.class).methodHandle(); 35.45 private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), IntArrayData.class, "setElem", void.class, int.class, int.class).methodHandle(); 35.46 35.47 @@ -104,7 +118,7 @@ 35.48 } 35.49 35.50 @Override 35.51 - public ArrayData copy() { 35.52 + public IntArrayData copy() { 35.53 return new IntArrayData(array.clone(), (int)length); 35.54 } 35.55 35.56 @@ -165,8 +179,7 @@ 35.57 public ArrayData convert(final Class<?> type) { 35.58 if (type == Integer.class) { 35.59 return this; 35.60 - } 35.61 - if (type == Long.class) { 35.62 + } else if (type == Long.class) { 35.63 return convertToLong(); 35.64 } else if (type == Double.class) { 35.65 return convertToDouble(); 35.66 @@ -209,8 +222,7 @@ 35.67 35.68 @Override 35.69 public ArrayData shrink(final long newLength) { 35.70 - Arrays.fill(array, (int) newLength, array.length, 0); 35.71 - 35.72 + Arrays.fill(array, (int)newLength, array.length, 0); 35.73 return this; 35.74 } 35.75 35.76 @@ -322,10 +334,7 @@ 35.77 35.78 @Override 35.79 public ArrayData slice(final long from, final long to) { 35.80 - final long start = from < 0 ? from + length : from; 35.81 - final long newLength = to - start; 35.82 - 35.83 - return new IntArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength); 35.84 + return new IntArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)(to - (from < 0 ? from + length : from))); 35.85 } 35.86 35.87 @Override 35.88 @@ -347,7 +356,13 @@ 35.89 throw new UnsupportedOperationException(); 35.90 } 35.91 final ArrayData returnValue = removed == 0 ? 35.92 - EMPTY_ARRAY : new IntArrayData(Arrays.copyOfRange(array, start, start + removed), removed); 35.93 + EMPTY_ARRAY : 35.94 + new IntArrayData( 35.95 + Arrays.copyOfRange( 35.96 + array, 35.97 + start, 35.98 + start + removed), 35.99 + removed); 35.100 35.101 if (newLength != oldLength) { 35.102 final int[] newArray; 35.103 @@ -403,4 +418,26 @@ 35.104 public Object fastPopObject() { 35.105 return fastPopInt(); 35.106 } 35.107 + 35.108 + @Override 35.109 + public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) { 35.110 + final int otherLength = (int)otherData.length; 35.111 + final int thisLength = (int)length; 35.112 + assert otherLength > 0 && thisLength > 0; 35.113 + 35.114 + final int[] otherArray = ((IntArrayData)otherData).array; 35.115 + final int newLength = otherLength + thisLength; 35.116 + final int[] newArray = new int[ArrayData.alignUp(newLength)]; 35.117 + 35.118 + System.arraycopy(array, 0, newArray, 0, thisLength); 35.119 + System.arraycopy(otherArray, 0, newArray, thisLength, otherLength); 35.120 + 35.121 + return new IntArrayData(newArray, newLength); 35.122 + } 35.123 + 35.124 + @Override 35.125 + public String toString() { 35.126 + assert length <= array.length : length + " > " + array.length; 35.127 + return getClass().getSimpleName() + ':' + Arrays.toString(Arrays.copyOf(array, (int)length)); 35.128 + } 35.129 }
36.1 --- a/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Wed Oct 29 10:50:44 2014 -0700 36.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Fri Oct 31 20:17:42 2014 -0700 36.3 @@ -52,16 +52,31 @@ 36.4 LongArrayData(final long array[], final int length) { 36.5 super(length); 36.6 assert array.length >= length; 36.7 - this.array = array; 36.8 + this.array = array; 36.9 } 36.10 36.11 @Override 36.12 - public Class<?> getElementType() { 36.13 + public final Class<?> getElementType() { 36.14 return long.class; 36.15 } 36.16 36.17 @Override 36.18 - public ArrayData copy() { 36.19 + public final Class<?> getBoxedElementType() { 36.20 + return Long.class; 36.21 + } 36.22 + 36.23 + @Override 36.24 + public final ContinuousArrayData widest(final ContinuousArrayData otherData) { 36.25 + return otherData instanceof IntElements ? this : otherData; 36.26 + } 36.27 + 36.28 + @Override 36.29 + public final int getElementWeight() { 36.30 + return 2; 36.31 + } 36.32 + 36.33 + @Override 36.34 + public LongArrayData copy() { 36.35 return new LongArrayData(array.clone(), (int)length); 36.36 } 36.37 36.38 @@ -101,7 +116,7 @@ 36.39 } 36.40 36.41 @Override 36.42 - public ArrayData convert(final Class<?> type) { 36.43 + public ContinuousArrayData convert(final Class<?> type) { 36.44 if (type == Integer.class || type == Long.class) { 36.45 return this; 36.46 } 36.47 @@ -145,8 +160,7 @@ 36.48 36.49 @Override 36.50 public ArrayData shrink(final long newLength) { 36.51 - Arrays.fill(array, (int) newLength, array.length, 0); 36.52 - 36.53 + Arrays.fill(array, (int)newLength, array.length, 0L); 36.54 return this; 36.55 } 36.56 36.57 @@ -359,4 +373,37 @@ 36.58 public Object fastPopObject() { 36.59 return fastPopLong(); 36.60 } 36.61 + 36.62 + @Override 36.63 + public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) { 36.64 + final int otherLength = (int)otherData.length; 36.65 + final int thisLength = (int)length; 36.66 + assert otherLength > 0 && thisLength > 0; 36.67 + 36.68 + final long[] otherArray = ((LongArrayData)otherData).array; 36.69 + final int newLength = otherLength + thisLength; 36.70 + final long[] newArray = new long[ArrayData.alignUp(newLength)]; 36.71 + 36.72 + System.arraycopy(array, 0, newArray, 0, thisLength); 36.73 + System.arraycopy(otherArray, 0, newArray, thisLength, otherLength); 36.74 + 36.75 + return new LongArrayData(newArray, newLength); 36.76 + } 36.77 + 36.78 + @Override 36.79 + public String toString() { 36.80 + assert length <= array.length : length + " > " + array.length; 36.81 + 36.82 + final StringBuilder sb = new StringBuilder(getClass().getSimpleName()). 36.83 + append(": ["); 36.84 + for (int i = 0; i < length; i++) { 36.85 + sb.append(array[i]).append('L'); //make sure L suffix is on elements, to discriminate this from IntArrayData.toString() 36.86 + if (i + 1 < length) { 36.87 + sb.append(", "); 36.88 + } 36.89 + } 36.90 + sb.append(']'); 36.91 + 36.92 + return sb.toString(); 36.93 + } 36.94 }
37.1 --- a/src/jdk/nashorn/internal/runtime/arrays/NoTypeArrayData.java Wed Oct 29 10:50:44 2014 -0700 37.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 37.3 @@ -1,186 +0,0 @@ 37.4 -/* 37.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 37.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 - * 37.8 - * This code is free software; you can redistribute it and/or modify it 37.9 - * under the terms of the GNU General Public License version 2 only, as 37.10 - * published by the Free Software Foundation. Oracle designates this 37.11 - * particular file as subject to the "Classpath" exception as provided 37.12 - * by Oracle in the LICENSE file that accompanied this code. 37.13 - * 37.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 37.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.17 - * version 2 for more details (a copy is included in the LICENSE file that 37.18 - * accompanied this code). 37.19 - * 37.20 - * You should have received a copy of the GNU General Public License version 37.21 - * 2 along with this work; if not, write to the Free Software Foundation, 37.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.23 - * 37.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 37.25 - * or visit www.oracle.com if you need additional information or have any 37.26 - * questions. 37.27 - */ 37.28 - 37.29 -package jdk.nashorn.internal.runtime.arrays; 37.30 - 37.31 -import java.lang.reflect.Array; 37.32 -import jdk.nashorn.internal.runtime.ScriptRuntime; 37.33 - 37.34 -/** 37.35 - * Place holding array data for non-array objects. Activates a true array when 37.36 - * accessed. Should only exist as a singleton defined in ArrayData. 37.37 - */ 37.38 -final class NoTypeArrayData extends ArrayData { 37.39 - NoTypeArrayData() { 37.40 - super(0); 37.41 - } 37.42 - 37.43 - NoTypeArrayData(final long length) { 37.44 - super(length); 37.45 - } 37.46 - 37.47 - @Override 37.48 - public Object[] asObjectArray() { 37.49 - return ScriptRuntime.EMPTY_ARRAY; 37.50 - } 37.51 - 37.52 - @Override 37.53 - public ArrayData copy() { 37.54 - return new NoTypeArrayData(); 37.55 - } 37.56 - 37.57 - @Override 37.58 - public Object asArrayOfType(final Class<?> componentType) { 37.59 - return Array.newInstance(componentType, 0); 37.60 - } 37.61 - 37.62 - @Override 37.63 - public ArrayData convert(final Class<?> type) { 37.64 - final long len = length; 37.65 - final ArrayData arrayData; 37.66 - if (type == Long.class) { 37.67 - arrayData = new LongArrayData(new long[ArrayData.nextSize((int)len)], (int)len); 37.68 - } else if (type == Double.class) { 37.69 - arrayData = new NumberArrayData(new double[ArrayData.nextSize((int)len)], (int)len); 37.70 - } else if (type == Integer.class) { 37.71 - arrayData = new IntArrayData(new int[ArrayData.nextSize((int)len)], (int)len); 37.72 - } else { 37.73 - assert !type.isPrimitive(); 37.74 - arrayData = new ObjectArrayData(new Object[ArrayData.nextSize((int)len)], (int)len); 37.75 - } 37.76 - return length == 0 ? arrayData : new DeletedRangeArrayFilter(arrayData, 0, len - 1); 37.77 - } 37.78 - 37.79 - @Override 37.80 - public void shiftLeft(final int by) { 37.81 - //empty 37.82 - } 37.83 - 37.84 - @Override 37.85 - public ArrayData shiftRight(final int by) { 37.86 - return this; 37.87 - } 37.88 - 37.89 - @Override 37.90 - public ArrayData ensure(final long safeIndex) { 37.91 - if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) { 37.92 - return new SparseArrayData(this, safeIndex + 1); 37.93 - } 37.94 - 37.95 - // Don't trample the shared EMPTY_ARRAY. 37.96 - if (length == 0) { 37.97 - return new NoTypeArrayData(Math.max(safeIndex + 1, length)); 37.98 - } 37.99 - 37.100 - setLength(Math.max(safeIndex + 1, length)); 37.101 - return this; 37.102 - } 37.103 - 37.104 - @Override 37.105 - public ArrayData shrink(final long newLength) { 37.106 - return this; 37.107 - } 37.108 - 37.109 - @Override 37.110 - public ArrayData set(final int index, final Object value, final boolean strict) { 37.111 - ArrayData newData; 37.112 - 37.113 - if (value instanceof Double) { 37.114 - newData = convert(Double.class); 37.115 - } else if (value instanceof Long) { 37.116 - newData = convert(Long.class); 37.117 - } else if (value instanceof Integer) { 37.118 - newData = convert(Integer.class); 37.119 - } else { 37.120 - assert !(value instanceof Number); 37.121 - newData = convert(value == null ? Object.class : value.getClass()); 37.122 - } 37.123 - 37.124 - return newData.set(index, value, strict); 37.125 - } 37.126 - 37.127 - @Override 37.128 - public ArrayData set(final int index, final int value, final boolean strict) { 37.129 - final ArrayData newData = convert(Integer.class); 37.130 - return newData.set(index, value, strict); 37.131 - } 37.132 - 37.133 - @Override 37.134 - public ArrayData set(final int index, final long value, final boolean strict) { 37.135 - final ArrayData newData = convert(Long.class); 37.136 - return newData.set(index, value, strict); 37.137 - } 37.138 - 37.139 - @Override 37.140 - public ArrayData set(final int index, final double value, final boolean strict) { 37.141 - final ArrayData newData = convert(Double.class); 37.142 - return newData.set(index, value, strict); 37.143 - } 37.144 - 37.145 - @Override 37.146 - public int getInt(final int index) { 37.147 - throw new ArrayIndexOutOfBoundsException(index); 37.148 - } 37.149 - 37.150 - @Override 37.151 - public long getLong(final int index) { 37.152 - throw new ArrayIndexOutOfBoundsException(index); 37.153 - } 37.154 - 37.155 - @Override 37.156 - public double getDouble(final int index) { 37.157 - throw new ArrayIndexOutOfBoundsException(index); 37.158 - } 37.159 - 37.160 - @Override 37.161 - public Object getObject(final int index) { 37.162 - throw new ArrayIndexOutOfBoundsException(index); 37.163 - } 37.164 - 37.165 - @Override 37.166 - public boolean has(final int index) { 37.167 - return false; 37.168 - } 37.169 - 37.170 - @Override 37.171 - public ArrayData delete(final int index) { 37.172 - return new DeletedRangeArrayFilter(this, index, index); 37.173 - } 37.174 - 37.175 - @Override 37.176 - public ArrayData delete(final long fromIndex, final long toIndex) { 37.177 - return new DeletedRangeArrayFilter(this, fromIndex, toIndex); 37.178 - } 37.179 - 37.180 - @Override 37.181 - public Object pop() { 37.182 - return ScriptRuntime.UNDEFINED; 37.183 - } 37.184 - 37.185 - @Override 37.186 - public ArrayData slice(final long from, final long to) { 37.187 - return this; 37.188 - } 37.189 -}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/NonExtensibleArrayFilter.java Fri Oct 31 20:17:42 2014 -0700 38.3 @@ -0,0 +1,68 @@ 38.4 +package jdk.nashorn.internal.runtime.arrays; 38.5 + 38.6 +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 38.7 +import jdk.nashorn.internal.objects.Global; 38.8 +import jdk.nashorn.internal.runtime.ScriptRuntime; 38.9 + 38.10 +/** 38.11 + * Filter class that wrap arrays that have been tagged non extensible 38.12 + */ 38.13 +public class NonExtensibleArrayFilter extends ArrayFilter { 38.14 + 38.15 + /** 38.16 + * Constructor 38.17 + * @param underlying array 38.18 + */ 38.19 + public NonExtensibleArrayFilter(final ArrayData underlying) { 38.20 + super(underlying); 38.21 + } 38.22 + 38.23 + @Override 38.24 + public ArrayData copy() { 38.25 + return new NonExtensibleArrayFilter(underlying.copy()); 38.26 + } 38.27 + 38.28 + @Override 38.29 + public ArrayData slice(final long from, final long to) { 38.30 + return new NonExtensibleArrayFilter(underlying.slice(from, to)); 38.31 + } 38.32 + 38.33 + private ArrayData extensionCheck(final boolean strict, final int index) { 38.34 + if (!strict) { 38.35 + return this; 38.36 + } 38.37 + throw typeError(Global.instance(), "object.non.extensible", String.valueOf(index), ScriptRuntime.safeToString(this)); 38.38 + } 38.39 + 38.40 + @Override 38.41 + public ArrayData set(final int index, final Object value, final boolean strict) { 38.42 + if (has(index)) { 38.43 + return underlying.set(index, value, strict); 38.44 + } 38.45 + return extensionCheck(strict, index); 38.46 + } 38.47 + 38.48 + @Override 38.49 + public ArrayData set(final int index, final int value, final boolean strict) { 38.50 + if (has(index)) { 38.51 + return underlying.set(index, value, strict); 38.52 + } 38.53 + return extensionCheck(strict, index); 38.54 + } 38.55 + 38.56 + @Override 38.57 + public ArrayData set(final int index, final long value, final boolean strict) { 38.58 + if (has(index)) { 38.59 + return underlying.set(index, value, strict); 38.60 + } 38.61 + return extensionCheck(strict, index); 38.62 + } 38.63 + 38.64 + @Override 38.65 + public ArrayData set(final int index, final double value, final boolean strict) { 38.66 + if (has(index)) { 38.67 + return underlying.set(index, value, strict); 38.68 + } 38.69 + return extensionCheck(strict, index); 38.70 + } 38.71 +}
39.1 --- a/src/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java Wed Oct 29 10:50:44 2014 -0700 39.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java Fri Oct 31 20:17:42 2014 -0700 39.3 @@ -48,19 +48,34 @@ 39.4 * @param array an int array 39.5 * @param length a length, not necessarily array.length 39.6 */ 39.7 - NumberArrayData(final double array[], final int length) { 39.8 + NumberArrayData(final double[] array, final int length) { 39.9 super(length); 39.10 assert array.length >= length; 39.11 - this.array = array; 39.12 + this.array = array; 39.13 } 39.14 39.15 @Override 39.16 - public Class<?> getElementType() { 39.17 + public final Class<?> getElementType() { 39.18 return double.class; 39.19 } 39.20 39.21 @Override 39.22 - public ArrayData copy() { 39.23 + public final Class<?> getBoxedElementType() { 39.24 + return Double.class; 39.25 + } 39.26 + 39.27 + @Override 39.28 + public final int getElementWeight() { 39.29 + return 3; 39.30 + } 39.31 + 39.32 + @Override 39.33 + public final ContinuousArrayData widest(final ContinuousArrayData otherData) { 39.34 + return otherData instanceof IntOrLongElements ? this : otherData; 39.35 + } 39.36 + 39.37 + @Override 39.38 + public NumberArrayData copy() { 39.39 return new NumberArrayData(array.clone(), (int)length); 39.40 } 39.41 39.42 @@ -88,7 +103,7 @@ 39.43 } 39.44 39.45 @Override 39.46 - public ArrayData convert(final Class<?> type) { 39.47 + public ContinuousArrayData convert(final Class<?> type) { 39.48 if (type != Double.class && type != Integer.class && type != Long.class) { 39.49 final int len = (int)length; 39.50 return new ObjectArrayData(toObjectArray(false), len); 39.51 @@ -129,7 +144,7 @@ 39.52 39.53 @Override 39.54 public ArrayData shrink(final long newLength) { 39.55 - Arrays.fill(array, (int) newLength, array.length, 0.0); 39.56 + Arrays.fill(array, (int)newLength, array.length, 0.0); 39.57 return this; 39.58 } 39.59 39.60 @@ -334,4 +349,26 @@ 39.61 public Object fastPopObject() { 39.62 return fastPopDouble(); 39.63 } 39.64 + 39.65 + @Override 39.66 + public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) { 39.67 + final int otherLength = (int)otherData.length; 39.68 + final int thisLength = (int)length; 39.69 + assert otherLength > 0 && thisLength > 0; 39.70 + 39.71 + final double[] otherArray = ((NumberArrayData)otherData).array; 39.72 + final int newLength = otherLength + thisLength; 39.73 + final double[] newArray = new double[ArrayData.alignUp(newLength)]; 39.74 + 39.75 + System.arraycopy(array, 0, newArray, 0, thisLength); 39.76 + System.arraycopy(otherArray, 0, newArray, thisLength, otherLength); 39.77 + 39.78 + return new NumberArrayData(newArray, newLength); 39.79 + } 39.80 + 39.81 + @Override 39.82 + public String toString() { 39.83 + assert length <= array.length : length + " > " + array.length; 39.84 + return getClass().getSimpleName() + ':' + Arrays.toString(Arrays.copyOf(array, (int)length)); 39.85 + } 39.86 }
40.1 --- a/src/jdk/nashorn/internal/runtime/arrays/NumericElements.java Wed Oct 29 10:50:44 2014 -0700 40.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/NumericElements.java Fri Oct 31 20:17:42 2014 -0700 40.3 @@ -30,6 +30,6 @@ 40.4 * Used for type checks that throw ClassCastExceptions and force relinks 40.5 * for fast NativeArray specializations of builtin methods 40.6 */ 40.7 -public interface NumericElements { 40.8 +public interface NumericElements extends AnyElements { 40.9 //empty 40.10 }
41.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ObjectArrayData.java Wed Oct 29 10:50:44 2014 -0700 41.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ObjectArrayData.java Fri Oct 31 20:17:42 2014 -0700 41.3 @@ -37,7 +37,7 @@ 41.4 * Implementation of {@link ArrayData} as soon as an Object has been 41.5 * written to the array 41.6 */ 41.7 -final class ObjectArrayData extends ContinuousArrayData { 41.8 +final class ObjectArrayData extends ContinuousArrayData implements AnyElements { 41.9 41.10 /** 41.11 * The wrapped array 41.12 @@ -49,19 +49,34 @@ 41.13 * @param array an int array 41.14 * @param length a length, not necessarily array.length 41.15 */ 41.16 - ObjectArrayData(final Object array[], final int length) { 41.17 + ObjectArrayData(final Object[] array, final int length) { 41.18 super(length); 41.19 assert array.length >= length; 41.20 this.array = array; 41.21 } 41.22 41.23 @Override 41.24 - public Class<?> getElementType() { 41.25 + public final Class<?> getElementType() { 41.26 return Object.class; 41.27 } 41.28 41.29 @Override 41.30 - public ArrayData copy() { 41.31 + public final Class<?> getBoxedElementType() { 41.32 + return getElementType(); 41.33 + } 41.34 + 41.35 + @Override 41.36 + public final int getElementWeight() { 41.37 + return 4; 41.38 + } 41.39 + 41.40 + @Override 41.41 + public final ContinuousArrayData widest(final ContinuousArrayData otherData) { 41.42 + return otherData instanceof NumericElements ? this : otherData; 41.43 + } 41.44 + 41.45 + @Override 41.46 + public ObjectArrayData copy() { 41.47 return new ObjectArrayData(array.clone(), (int)length); 41.48 } 41.49 41.50 @@ -79,7 +94,7 @@ 41.51 } 41.52 41.53 @Override 41.54 - public ArrayData convert(final Class<?> type) { 41.55 + public ObjectArrayData convert(final Class<?> type) { 41.56 return this; 41.57 } 41.58 41.59 @@ -325,4 +340,26 @@ 41.60 41.61 return returnValue; 41.62 } 41.63 + 41.64 + @Override 41.65 + public ContinuousArrayData fastConcat(final ContinuousArrayData otherData) { 41.66 + final int otherLength = (int)otherData.length; 41.67 + final int thisLength = (int)length; 41.68 + assert otherLength > 0 && thisLength > 0; 41.69 + 41.70 + final Object[] otherArray = ((ObjectArrayData)otherData).array; 41.71 + final int newLength = otherLength + thisLength; 41.72 + final Object[] newArray = new Object[ArrayData.alignUp(newLength)]; 41.73 + 41.74 + System.arraycopy(array, 0, newArray, 0, thisLength); 41.75 + System.arraycopy(otherArray, 0, newArray, thisLength, otherLength); 41.76 + 41.77 + return new ObjectArrayData(newArray, newLength); 41.78 + } 41.79 + 41.80 + @Override 41.81 + public String toString() { 41.82 + assert length <= array.length : length + " > " + array.length; 41.83 + return getClass().getSimpleName() + ':' + Arrays.toString(Arrays.copyOf(array, (int)length)); 41.84 + } 41.85 }
42.1 --- a/src/jdk/nashorn/internal/runtime/arrays/TypedArrayData.java Wed Oct 29 10:50:44 2014 -0700 42.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/TypedArrayData.java Fri Oct 31 20:17:42 2014 -0700 42.3 @@ -88,7 +88,7 @@ 42.4 } 42.5 42.6 @Override 42.7 - public ArrayData copy() { 42.8 + public TypedArrayData<T> copy() { 42.9 throw new UnsupportedOperationException(); 42.10 } 42.11 42.12 @@ -133,7 +133,7 @@ 42.13 } 42.14 42.15 @Override 42.16 - public ArrayData convert(final Class<?> type) { 42.17 + public TypedArrayData<T> convert(final Class<?> type) { 42.18 throw new UnsupportedOperationException(); 42.19 } 42.20
43.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Wed Oct 29 10:50:44 2014 -0700 43.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Fri Oct 31 20:17:42 2014 -0700 43.3 @@ -337,6 +337,20 @@ 43.4 43.5 /** 43.6 * Returns a dynamic invoker for a specified dynamic operation using the public lookup. Similar to 43.7 + * {@link #createDynamicInvoker(String, Class, Class...)} but with an additional parameter to 43.8 + * set the call site flags of the dynamic invoker. 43.9 + * @param opDesc Dynalink dynamic operation descriptor. 43.10 + * @param flags the call site flags for the operation 43.11 + * @param rtype the return type for the operation 43.12 + * @param ptypes the parameter types for the operation 43.13 + * @return MethodHandle for invoking the operation. 43.14 + */ 43.15 + public static MethodHandle createDynamicInvoker(final String opDesc, final int flags, final Class<?> rtype, final Class<?>... ptypes) { 43.16 + return bootstrap(MethodHandles.publicLookup(), opDesc, MethodType.methodType(rtype, ptypes), flags).dynamicInvoker(); 43.17 + } 43.18 + 43.19 + /** 43.20 + * Returns a dynamic invoker for a specified dynamic operation using the public lookup. Similar to 43.21 * {@link #createDynamicInvoker(String, Class, Class...)} but with return and parameter types composed into a 43.22 * method type in the signature. See the discussion of that method for details. 43.23 * @param opDesc Dynalink dynamic operation descriptor.
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/examples/getter-setter-micro.js Fri Oct 31 20:17:42 2014 -0700 44.3 @@ -0,0 +1,81 @@ 44.4 +/* 44.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 44.6 + * 44.7 + * Redistribution and use in source and binary forms, with or without 44.8 + * modification, are permitted provided that the following conditions 44.9 + * are met: 44.10 + * 44.11 + * - Redistributions of source code must retain the above copyright 44.12 + * notice, this list of conditions and the following disclaimer. 44.13 + * 44.14 + * - Redistributions in binary form must reproduce the above copyright 44.15 + * notice, this list of conditions and the following disclaimer in the 44.16 + * documentation and/or other materials provided with the distribution. 44.17 + * 44.18 + * - Neither the name of Oracle nor the names of its 44.19 + * contributors may be used to endorse or promote products derived 44.20 + * from this software without specific prior written permission. 44.21 + * 44.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 44.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 44.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 44.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 44.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 44.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 44.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 44.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 44.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 44.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44.33 + */ 44.34 + 44.35 +/* 44.36 + * A micro-benchmark for getters and setters with primitive values, 44.37 + * alternating between ints and doubles. Introduction of primitive 44.38 + * and optimistic user accessors in JDK-8062401 make this faster by 44.39 + * 10x or more by allowing inlining and other optimizations to take place. 44.40 + */ 44.41 + 44.42 +var x = { 44.43 + get m() { 44.44 + return this._m; 44.45 + }, 44.46 + set m(v) { 44.47 + this._m = v; 44.48 + }, 44.49 + get n() { 44.50 + return this._n; 44.51 + }, 44.52 + set n(v) { 44.53 + this._n = v; 44.54 + } 44.55 +}; 44.56 + 44.57 + 44.58 +function bench(v1, v2, result) { 44.59 + var start = Date.now(); 44.60 + x.n = v1; 44.61 + for (var i = 0; i < 1e8; i++) { 44.62 + x.m = v2; 44.63 + if (x.m + x.n !== result) { 44.64 + throw "wrong result"; 44.65 + } 44.66 + } 44.67 + print("done in", Date.now() - start, "millis"); 44.68 +} 44.69 + 44.70 +for (var i = 0; i < 10; i++) { 44.71 + bench(i, 4, 4 + i); 44.72 +} 44.73 + 44.74 +for (var i = 0; i < 10; i++) { 44.75 + bench(i, 4.5, 4.5 + i); 44.76 +} 44.77 + 44.78 +for (var i = 0; i < 10; i++) { 44.79 + bench(i, 5, 5 + i); 44.80 +} 44.81 + 44.82 +for (var i = 0; i < 10; i++) { 44.83 + bench(i, 5.5, 5.5 + i); 44.84 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/script/basic/JDK-8061391.js Fri Oct 31 20:17:42 2014 -0700 45.3 @@ -0,0 +1,151 @@ 45.4 +/* 45.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. 45.11 + * 45.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.15 + * version 2 for more details (a copy is included in the LICENSE file that 45.16 + * accompanied this code). 45.17 + * 45.18 + * You should have received a copy of the GNU General Public License version 45.19 + * 2 along with this work; if not, write to the Free Software Foundation, 45.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.21 + * 45.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.23 + * or visit www.oracle.com if you need additional information or have any 45.24 + * questions. 45.25 + */ 45.26 + 45.27 +/** 45.28 + * JDK-8061391 - Checks that the optimistic builtin for concat is semantically 45.29 + * correct. 45.30 + * 45.31 + * @test 45.32 + * @run 45.33 + */ 45.34 + 45.35 +var maxJavaInt = 0x7fffffff; 45.36 + 45.37 +var ia = [1, 2, 3, 4]; 45.38 +var la = [maxJavaInt + 1000, maxJavaInt + 2000, maxJavaInt + 3000, maxJavaInt + 4000]; 45.39 +var da = [1.1, 2.2, 3.3, 4.4]; 45.40 +var oa = ["one", "two", "three", "four"]; 45.41 + 45.42 +var aa = [ia, la, da, oa]; 45.43 + 45.44 +function concats() { 45.45 + print("shared callsite"); 45.46 + 45.47 + print(ia); 45.48 + print(la); 45.49 + print(da); 45.50 + print(oa); 45.51 + print(aa); 45.52 + 45.53 + for (var i = 0; i < aa.length; i++) { 45.54 + print(aa[i].concat(aa[i][0])); 45.55 + for (var j = 0; j < aa.length ; j++) { 45.56 + print(aa[i].concat(aa[j])); 45.57 + } 45.58 + } 45.59 +} 45.60 + 45.61 +function concats_inline() { 45.62 + print("separate callsites"); 45.63 + 45.64 + print(ia); 45.65 + print(la); 45.66 + print(da); 45.67 + print(oa); 45.68 + print(aa); 45.69 + 45.70 + print(aa[0].concat(aa[0])); 45.71 + print(aa[0].concat(aa[1])); 45.72 + print(aa[0].concat(aa[2])); 45.73 + print(aa[0].concat(aa[3])); 45.74 + print(aa[0].concat(aa[0][0])); 45.75 + 45.76 + print(aa[1].concat(aa[0])); 45.77 + print(aa[1].concat(aa[1])); 45.78 + print(aa[1].concat(aa[2])); 45.79 + print(aa[1].concat(aa[3])); 45.80 + print(aa[1].concat(aa[1][0])); 45.81 + 45.82 + print(aa[2].concat(aa[0])); 45.83 + print(aa[2].concat(aa[1])); 45.84 + print(aa[2].concat(aa[2])); 45.85 + print(aa[2].concat(aa[3])); 45.86 + print(aa[2].concat(aa[2][0])); 45.87 + 45.88 + print(aa[3].concat(aa[0])); 45.89 + print(aa[3].concat(aa[1])); 45.90 + print(aa[3].concat(aa[2])); 45.91 + print(aa[3].concat(aa[3])); 45.92 + print(aa[3].concat(aa[3][0])); 45.93 +} 45.94 + 45.95 +concats(); 45.96 +concats_inline(); 45.97 + 45.98 +print(); 45.99 +var oldia = ia.slice(0); //clone ia 45.100 +print("oldia = " + oldia); 45.101 +ia[10] = "sparse"; 45.102 +print("oldia = " + oldia); 45.103 + 45.104 +print(); 45.105 +print("Redoing with sparse arrays"); 45.106 + 45.107 +concats(); 45.108 +concats_inline(); 45.109 + 45.110 +ia = oldia; 45.111 +print("Restored ia = " + ia); 45.112 + 45.113 +function concat_expand() { 45.114 + print("concat type expansion"); 45.115 + print(ia.concat(la)); 45.116 + print(ia.concat(da)); 45.117 + print(ia.concat(oa)); 45.118 + print(la.concat(ia)); 45.119 + print(la.concat(da)); 45.120 + print(la.concat(oa)); 45.121 + print(da.concat(ia)); 45.122 + print(da.concat(la)); 45.123 + print(da.concat(oa)); 45.124 +} 45.125 + 45.126 +print(); 45.127 +concat_expand(); 45.128 + 45.129 +print(); 45.130 + 45.131 +function concat_varargs() { 45.132 + print("concat varargs"); 45.133 + print(ia.concat(la)); //fast 45.134 + print(ia.concat(la, da, oa)); //slow 45.135 + var slow = ia.concat(1, maxJavaInt * 2, 4711.17, function() { print("hello, world") }); //slow 45.136 + print(slow); 45.137 + return slow; 45.138 +} 45.139 + 45.140 +var slow = concat_varargs(); 45.141 + 45.142 +print(); 45.143 +print("sanity checks"); 45.144 +slow.map( 45.145 + function(elem) { 45.146 + if (elem instanceof Function) { 45.147 + elem(); 45.148 + } else { 45.149 + print((typeof elem) + " = " + elem); 45.150 + } 45.151 + }); 45.152 + 45.153 +print(ia.concat({key: "value"})); 45.154 +print(ia.concat({key: "value"}, {key2: "value2"}));
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/script/basic/JDK-8061391.js.EXPECTED Fri Oct 31 20:17:42 2014 -0700 46.3 @@ -0,0 +1,138 @@ 46.4 +shared callsite 46.5 +1,2,3,4 46.6 +2147484647,2147485647,2147486647,2147487647 46.7 +1.1,2.2,3.3,4.4 46.8 +one,two,three,four 46.9 +1,2,3,4,2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4,one,two,three,four 46.10 +1,2,3,4,1 46.11 +1,2,3,4,1,2,3,4 46.12 +1,2,3,4,2147484647,2147485647,2147486647,2147487647 46.13 +1,2,3,4,1.1,2.2,3.3,4.4 46.14 +1,2,3,4,one,two,three,four 46.15 +2147484647,2147485647,2147486647,2147487647,2147484647 46.16 +2147484647,2147485647,2147486647,2147487647,1,2,3,4 46.17 +2147484647,2147485647,2147486647,2147487647,2147484647,2147485647,2147486647,2147487647 46.18 +2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4 46.19 +2147484647,2147485647,2147486647,2147487647,one,two,three,four 46.20 +1.1,2.2,3.3,4.4,1.1 46.21 +1.1,2.2,3.3,4.4,1,2,3,4 46.22 +1.1,2.2,3.3,4.4,2147484647,2147485647,2147486647,2147487647 46.23 +1.1,2.2,3.3,4.4,1.1,2.2,3.3,4.4 46.24 +1.1,2.2,3.3,4.4,one,two,three,four 46.25 +one,two,three,four,one 46.26 +one,two,three,four,1,2,3,4 46.27 +one,two,three,four,2147484647,2147485647,2147486647,2147487647 46.28 +one,two,three,four,1.1,2.2,3.3,4.4 46.29 +one,two,three,four,one,two,three,four 46.30 +separate callsites 46.31 +1,2,3,4 46.32 +2147484647,2147485647,2147486647,2147487647 46.33 +1.1,2.2,3.3,4.4 46.34 +one,two,three,four 46.35 +1,2,3,4,2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4,one,two,three,four 46.36 +1,2,3,4,1,2,3,4 46.37 +1,2,3,4,2147484647,2147485647,2147486647,2147487647 46.38 +1,2,3,4,1.1,2.2,3.3,4.4 46.39 +1,2,3,4,one,two,three,four 46.40 +1,2,3,4,1 46.41 +2147484647,2147485647,2147486647,2147487647,1,2,3,4 46.42 +2147484647,2147485647,2147486647,2147487647,2147484647,2147485647,2147486647,2147487647 46.43 +2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4 46.44 +2147484647,2147485647,2147486647,2147487647,one,two,three,four 46.45 +2147484647,2147485647,2147486647,2147487647,2147484647 46.46 +1.1,2.2,3.3,4.4,1,2,3,4 46.47 +1.1,2.2,3.3,4.4,2147484647,2147485647,2147486647,2147487647 46.48 +1.1,2.2,3.3,4.4,1.1,2.2,3.3,4.4 46.49 +1.1,2.2,3.3,4.4,one,two,three,four 46.50 +1.1,2.2,3.3,4.4,1.1 46.51 +one,two,three,four,1,2,3,4 46.52 +one,two,three,four,2147484647,2147485647,2147486647,2147487647 46.53 +one,two,three,four,1.1,2.2,3.3,4.4 46.54 +one,two,three,four,one,two,three,four 46.55 +one,two,three,four,one 46.56 + 46.57 +oldia = 1,2,3,4 46.58 +oldia = 1,2,3,4 46.59 + 46.60 +Redoing with sparse arrays 46.61 +shared callsite 46.62 +1,2,3,4,,,,,,,sparse 46.63 +2147484647,2147485647,2147486647,2147487647 46.64 +1.1,2.2,3.3,4.4 46.65 +one,two,three,four 46.66 +1,2,3,4,,,,,,,sparse,2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4,one,two,three,four 46.67 +1,2,3,4,,,,,,,sparse,1 46.68 +1,2,3,4,,,,,,,sparse,1,2,3,4,,,,,,,sparse 46.69 +1,2,3,4,,,,,,,sparse,2147484647,2147485647,2147486647,2147487647 46.70 +1,2,3,4,,,,,,,sparse,1.1,2.2,3.3,4.4 46.71 +1,2,3,4,,,,,,,sparse,one,two,three,four 46.72 +2147484647,2147485647,2147486647,2147487647,2147484647 46.73 +2147484647,2147485647,2147486647,2147487647,1,2,3,4,,,,,,,sparse 46.74 +2147484647,2147485647,2147486647,2147487647,2147484647,2147485647,2147486647,2147487647 46.75 +2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4 46.76 +2147484647,2147485647,2147486647,2147487647,one,two,three,four 46.77 +1.1,2.2,3.3,4.4,1.1 46.78 +1.1,2.2,3.3,4.4,1,2,3,4,,,,,,,sparse 46.79 +1.1,2.2,3.3,4.4,2147484647,2147485647,2147486647,2147487647 46.80 +1.1,2.2,3.3,4.4,1.1,2.2,3.3,4.4 46.81 +1.1,2.2,3.3,4.4,one,two,three,four 46.82 +one,two,three,four,one 46.83 +one,two,three,four,1,2,3,4,,,,,,,sparse 46.84 +one,two,three,four,2147484647,2147485647,2147486647,2147487647 46.85 +one,two,three,four,1.1,2.2,3.3,4.4 46.86 +one,two,three,four,one,two,three,four 46.87 +separate callsites 46.88 +1,2,3,4,,,,,,,sparse 46.89 +2147484647,2147485647,2147486647,2147487647 46.90 +1.1,2.2,3.3,4.4 46.91 +one,two,three,four 46.92 +1,2,3,4,,,,,,,sparse,2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4,one,two,three,four 46.93 +1,2,3,4,,,,,,,sparse,1,2,3,4,,,,,,,sparse 46.94 +1,2,3,4,,,,,,,sparse,2147484647,2147485647,2147486647,2147487647 46.95 +1,2,3,4,,,,,,,sparse,1.1,2.2,3.3,4.4 46.96 +1,2,3,4,,,,,,,sparse,one,two,three,four 46.97 +1,2,3,4,,,,,,,sparse,1 46.98 +2147484647,2147485647,2147486647,2147487647,1,2,3,4,,,,,,,sparse 46.99 +2147484647,2147485647,2147486647,2147487647,2147484647,2147485647,2147486647,2147487647 46.100 +2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4 46.101 +2147484647,2147485647,2147486647,2147487647,one,two,three,four 46.102 +2147484647,2147485647,2147486647,2147487647,2147484647 46.103 +1.1,2.2,3.3,4.4,1,2,3,4,,,,,,,sparse 46.104 +1.1,2.2,3.3,4.4,2147484647,2147485647,2147486647,2147487647 46.105 +1.1,2.2,3.3,4.4,1.1,2.2,3.3,4.4 46.106 +1.1,2.2,3.3,4.4,one,two,three,four 46.107 +1.1,2.2,3.3,4.4,1.1 46.108 +one,two,three,four,1,2,3,4,,,,,,,sparse 46.109 +one,two,three,four,2147484647,2147485647,2147486647,2147487647 46.110 +one,two,three,four,1.1,2.2,3.3,4.4 46.111 +one,two,three,four,one,two,three,four 46.112 +one,two,three,four,one 46.113 +Restored ia = 1,2,3,4 46.114 + 46.115 +concat type expansion 46.116 +1,2,3,4,2147484647,2147485647,2147486647,2147487647 46.117 +1,2,3,4,1.1,2.2,3.3,4.4 46.118 +1,2,3,4,one,two,three,four 46.119 +2147484647,2147485647,2147486647,2147487647,1,2,3,4 46.120 +2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4 46.121 +2147484647,2147485647,2147486647,2147487647,one,two,three,four 46.122 +1.1,2.2,3.3,4.4,1,2,3,4 46.123 +1.1,2.2,3.3,4.4,2147484647,2147485647,2147486647,2147487647 46.124 +1.1,2.2,3.3,4.4,one,two,three,four 46.125 + 46.126 +concat varargs 46.127 +1,2,3,4,2147484647,2147485647,2147486647,2147487647 46.128 +1,2,3,4,2147484647,2147485647,2147486647,2147487647,1.1,2.2,3.3,4.4,one,two,three,four 46.129 +1,2,3,4,1,4294967294,4711.17,function() { print("hello, world") } 46.130 + 46.131 +sanity checks 46.132 +number = 1 46.133 +number = 2 46.134 +number = 3 46.135 +number = 4 46.136 +number = 1 46.137 +number = 4294967294 46.138 +number = 4711.17 46.139 +hello, world 46.140 +1,2,3,4,[object Object] 46.141 +1,2,3,4,[object Object],[object Object]
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/script/basic/JDK-8061391_2.js Fri Oct 31 20:17:42 2014 -0700 47.3 @@ -0,0 +1,52 @@ 47.4 +/* 47.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. 47.11 + * 47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 + * version 2 for more details (a copy is included in the LICENSE file that 47.16 + * accompanied this code). 47.17 + * 47.18 + * You should have received a copy of the GNU General Public License version 47.19 + * 2 along with this work; if not, write to the Free Software Foundation, 47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 + * 47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 + * or visit www.oracle.com if you need additional information or have any 47.24 + * questions. 47.25 + */ 47.26 + 47.27 +/** 47.28 + * Array extension check 47.29 + * 47.30 + * @test 47.31 + * @run 47.32 + */ 47.33 + 47.34 +"use strict"; 47.35 +var a = [1,2,3]; 47.36 +Object.preventExtensions(a); 47.37 +try { 47.38 + a[4] = 4; 47.39 + print(a); 47.40 +} catch (e) { 47.41 + if (!(e instanceof TypeError)) { 47.42 + print("TypeError expected but got e"); 47.43 + } 47.44 +} 47.45 + 47.46 +if (a[0] != 1) { 47.47 + throw "element 0 is wrong"; 47.48 +} 47.49 +if (a[1] != 2) { 47.50 + throw "element 1 is wrong"; 47.51 +} 47.52 +if (a[2] != 3) { 47.53 + throw "element 2 is wrong"; 47.54 +} 47.55 +
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/script/basic/JDK-8061391_3.js Fri Oct 31 20:17:42 2014 -0700 48.3 @@ -0,0 +1,44 @@ 48.4 +/* 48.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. 48.11 + * 48.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.15 + * version 2 for more details (a copy is included in the LICENSE file that 48.16 + * accompanied this code). 48.17 + * 48.18 + * You should have received a copy of the GNU General Public License version 48.19 + * 2 along with this work; if not, write to the Free Software Foundation, 48.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.21 + * 48.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.23 + * or visit www.oracle.com if you need additional information or have any 48.24 + * questions. 48.25 + */ 48.26 + 48.27 +/** 48.28 + * Array extension check 48.29 + * 48.30 + * @test 48.31 + * @run 48.32 + */ 48.33 + 48.34 +var a = [1,2,3]; 48.35 +Object.preventExtensions(a); 48.36 +a[4] = 4; 48.37 +print(a); 48.38 +if (a[0] != 1) { 48.39 + throw "element 0 is wrong"; 48.40 +} 48.41 +if (a[1] != 2) { 48.42 + throw "element 1 is wrong"; 48.43 +} 48.44 +if (a[2] != 3) { 48.45 + throw "element 2 is wrong"; 48.46 +} 48.47 +
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/script/basic/JDK-8061391_3.js.EXPECTED Fri Oct 31 20:17:42 2014 -0700 49.3 @@ -0,0 +1,1 @@ 49.4 +1,2,3
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/script/basic/JDK-8062024.js Fri Oct 31 20:17:42 2014 -0700 50.3 @@ -0,0 +1,40 @@ 50.4 +/* 50.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. 50.11 + * 50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.15 + * version 2 for more details (a copy is included in the LICENSE file that 50.16 + * accompanied this code). 50.17 + * 50.18 + * You should have received a copy of the GNU General Public License version 50.19 + * 2 along with this work; if not, write to the Free Software Foundation, 50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.21 + * 50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.23 + * or visit www.oracle.com if you need additional information or have any 50.24 + * questions. 50.25 + */ 50.26 + 50.27 +/** 50.28 + * JDK-8062024: Issue with date.setFullYear when time other than midnight 50.29 + * 50.30 + * @test 50.31 + * @option -timezone=Asia/Calcutta 50.32 + * @run 50.33 + */ 50.34 + 50.35 +var date1 = new Date("January 01, 1950 00:00:00"); 50.36 +print("Before:", date1); 50.37 +date1.setFullYear(1960); 50.38 +print("After:", date1); 50.39 + 50.40 +var date2 = new Date("January 01, 1950 00:00:01"); 50.41 +print("Before:", date2); 50.42 +date2.setFullYear(1960); 50.43 +print("After:", date2);
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/script/basic/JDK-8062024.js.EXPECTED Fri Oct 31 20:17:42 2014 -0700 51.3 @@ -0,0 +1,4 @@ 51.4 +Before: Sun Jan 01 1950 00:00:00 GMT+0530 (IST) 51.5 +After: Fri Jan 01 1960 00:00:00 GMT+0530 (IST) 51.6 +Before: Sun Jan 01 1950 00:00:01 GMT+0530 (IST) 51.7 +After: Fri Jan 01 1960 00:00:01 GMT+0530 (IST)
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/script/basic/JDK-8062132.js Fri Oct 31 20:17:42 2014 -0700 52.3 @@ -0,0 +1,80 @@ 52.4 +/* 52.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. 52.11 + * 52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.15 + * version 2 for more details (a copy is included in the LICENSE file that 52.16 + * accompanied this code). 52.17 + * 52.18 + * You should have received a copy of the GNU General Public License version 52.19 + * 2 along with this work; if not, write to the Free Software Foundation, 52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.21 + * 52.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.23 + * or visit www.oracle.com if you need additional information or have any 52.24 + * questions. 52.25 + */ 52.26 + 52.27 +/** 52.28 + * 8062132: Nashorn incorrectly binds "this" for constructor created by another function 52.29 + * 52.30 + * @test 52.31 + * @run 52.32 + */ 52.33 + 52.34 +function subclass(parentCtor, proto) { 52.35 + function C() { 52.36 + parentCtor.call(this); 52.37 + } 52.38 + 52.39 + C.prototype = Object.create(parentCtor.prototype); 52.40 + 52.41 + for (var prop in proto) { 52.42 + if (proto.hasOwnProperty(prop)) { 52.43 + C.prototype[prop] = proto[prop]; 52.44 + } 52.45 + } 52.46 + 52.47 + return C; 52.48 +} 52.49 + 52.50 +var Parent = function() { 52.51 + this.init(); 52.52 +}; 52.53 + 52.54 +Parent.prototype = { 52.55 + init: null 52.56 +}; 52.57 + 52.58 +var Child1 = subclass(Parent, { 52.59 + prop1: 1, 52.60 + init: function() { 52.61 + print('child 1'); 52.62 + } 52.63 +}); 52.64 + 52.65 +var Child2 = subclass(Parent, { 52.66 + init: function() { 52.67 + print('child 2'); 52.68 + } 52.69 +}); 52.70 + 52.71 +var Child3 = subclass(Parent, { 52.72 + prop1: 1, 52.73 + init: function() { 52.74 + print('child 3'); 52.75 + } 52.76 +}); 52.77 + 52.78 +new Child1(); 52.79 +new Child2(); 52.80 +new Child3(); 52.81 +new Child1(); 52.82 +new Child2(); 52.83 +new Child3();
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/script/basic/JDK-8062132.js.EXPECTED Fri Oct 31 20:17:42 2014 -0700 53.3 @@ -0,0 +1,6 @@ 53.4 +child 1 53.5 +child 2 53.6 +child 3 53.7 +child 1 53.8 +child 2 53.9 +child 3
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/script/basic/JDK-8062583.js Fri Oct 31 20:17:42 2014 -0700 54.3 @@ -0,0 +1,51 @@ 54.4 +/* 54.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. 54.11 + * 54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.15 + * version 2 for more details (a copy is included in the LICENSE file that 54.16 + * accompanied this code). 54.17 + * 54.18 + * You should have received a copy of the GNU General Public License version 54.19 + * 2 along with this work; if not, write to the Free Software Foundation, 54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.21 + * 54.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.23 + * or visit www.oracle.com if you need additional information or have any 54.24 + * questions. 54.25 + */ 54.26 + 54.27 +/** 54.28 + * JDK-8062583: Throwing object with error prototype causes error proto to be caught 54.29 + * 54.30 + * @test 54.31 + * @run 54.32 + */ 54.33 + 54.34 +function CustomError() { 54.35 + this.name = "CustomError"; 54.36 +} 54.37 + 54.38 +CustomError.prototype = new Error(); 54.39 + 54.40 +var c1 = new CustomError(); 54.41 + 54.42 +try { 54.43 + throw c1; 54.44 +} catch (e) { 54.45 + print(e === c1); 54.46 + print(e === CustomError.prototype); 54.47 + print(e.stack.replace(/\\/g, '/')); 54.48 + print(e.nashornException.toString().replace(/\\/g, '/')); 54.49 +} 54.50 + 54.51 +var c2 = new CustomError(); 54.52 +Error.captureStackTrace(c2); 54.53 +print(c2.stack.replace(/\\/g, '/')); 54.54 +print(c2.nashornException.toString().replace(/\\/g, '/'));
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/script/basic/JDK-8062583.js.EXPECTED Fri Oct 31 20:17:42 2014 -0700 55.3 @@ -0,0 +1,8 @@ 55.4 +true 55.5 +false 55.6 +CustomError 55.7 + at <program> (test/script/basic/JDK-8062583.js:40) 55.8 +test/script/basic/JDK-8062583.js:40:4 CustomError 55.9 +CustomError 55.10 + at <program> (test/script/basic/JDK-8062583.js:49) 55.11 +test/script/basic/JDK-8062583.js:49 CustomError