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

Wed, 30 Jan 2013 12:26:45 +0100

author
lagergren
date
Wed, 30 Jan 2013 12:26:45 +0100
changeset 57
59970b70ebb5
parent 44
e62dba3ce52b
child 112
267cc4c85160
permissions
-rw-r--r--

8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
Summary: Lower suffered from being a "God class" trying to do everything at once. As Nashorn code generation has grown, so has Lower. It does several post processing passes, tries to do several things at once even though all type information isn't in place, adjusting state afterwards and so on. It also performs control flow analysis, type attribution and constant folding, and everything else code generation related before byte code emission. I have now separated the compilation process into Lower (create low level nodes from high level ones, copy code such as finally block inlining etc), Attr (assign types and symbols to all nodes - freeze slot and scope information) and FinalizeTypes (insert explicit casts, specialize invoke dynamic types for scope accesses). I've removed the kludgy AccessSpecializer, as this now integrates naturally with typing. Everything is now much easier to read and each module performs only one thing. I have added separate loggers for the separate tiers. In the process I have also fixed: (1) problems with type coercion (see test/script/basic/typecoercion.js, basically our coercion was too late and our symbol inference was erroneous. This only manifested itself in very rare occasions where toNumber coercion has side effects, such as for example when valueOf is overridden) (2) copying literal nodes (literal copy did not use the superclass copy, which made all the Node specific fields not to be copied (3) erroneous literal tokenization (literals shouldn't always just inherit token information from whatever node that creates them) (4) splitter weighnodes - unary nodes were considered weightless (4) removed the hateful and kludgy "VarNode.shouldAppend", which really isn't needed when we have an attribution phase that determines self reference symbols (the only thing it was used for) (5) duplicate line number issues in the parser (6) convert bug in CodeGenerator for intermediate results of scope accesses (see test/script/basic/access-specializer.js) ... Several of these things just stopped being problems with the new architecture "can't happen anymore" and are not bug fixes per se. All tests run. No performance regressions exist that I've been able to measure. Some increases in performance were measured, but in the statistical margin of error (which is very wide as HotSpot currently has warmup issues with LambdaForms/invoke dynamic). Compile speed has not measurably increased.
Reviewed-by: jlaskey, attila

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jlaskey@3 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation. Oracle designates this
jlaskey@3 8 * particular file as subject to the "Classpath" exception as provided
jlaskey@3 9 * by Oracle in the LICENSE file that accompanied this code.
jlaskey@3 10 *
jlaskey@3 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 14 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 15 * accompanied this code).
jlaskey@3 16 *
jlaskey@3 17 * You should have received a copy of the GNU General Public License version
jlaskey@3 18 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jlaskey@3 20 *
jlaskey@3 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 22 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 23 * questions.
jlaskey@3 24 */
jlaskey@3 25
jlaskey@3 26 package jdk.nashorn.internal.runtime.arrays;
jlaskey@3 27
jlaskey@3 28 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
jlaskey@3 29
jlaskey@3 30 import jdk.nashorn.internal.runtime.GlobalObject;
jlaskey@3 31 import jdk.nashorn.internal.runtime.PropertyDescriptor;
jlaskey@3 32
jlaskey@3 33 /**
jlaskey@3 34 * ArrayData after the array has been frozen by Object.freeze call.
jlaskey@3 35 */
jlaskey@3 36 final class FrozenArrayFilter extends SealedArrayFilter {
jlaskey@3 37 FrozenArrayFilter(final ArrayData underlying) {
jlaskey@3 38 super(underlying);
jlaskey@3 39 }
jlaskey@3 40
jlaskey@3 41 @Override
jlaskey@3 42 public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
jlaskey@3 43 return global.newDataDescriptor(getObject(index), false, true, false);
jlaskey@3 44 }
jlaskey@3 45
jlaskey@3 46 @Override
jlaskey@3 47 public ArrayData set(final int index, final int value, final boolean strict) {
jlaskey@3 48 if (strict) {
sundar@44 49 typeError("cant.set.property", Integer.toString(index), "frozen array");
jlaskey@3 50 }
jlaskey@3 51 return this;
jlaskey@3 52 }
jlaskey@3 53
jlaskey@3 54 @Override
jlaskey@3 55 public ArrayData set(final int index, final long value, final boolean strict) {
jlaskey@3 56 if (strict) {
sundar@44 57 typeError("cant.set.property", Integer.toString(index), "frozen array");
jlaskey@3 58 }
jlaskey@3 59 return this;
jlaskey@3 60 }
jlaskey@3 61
jlaskey@3 62 @Override
jlaskey@3 63 public ArrayData set(final int index, final double value, final boolean strict) {
jlaskey@3 64 if (strict) {
sundar@44 65 typeError("cant.set.property", Integer.toString(index), "frozen array");
jlaskey@3 66 }
jlaskey@3 67 return this;
jlaskey@3 68 }
jlaskey@3 69
jlaskey@3 70 @Override
jlaskey@3 71 public ArrayData set(final int index, final Object value, final boolean strict) {
jlaskey@3 72 if (strict) {
sundar@44 73 typeError("cant.set.property", Integer.toString(index), "frozen array");
jlaskey@3 74 }
jlaskey@3 75 return this;
jlaskey@3 76 }
jlaskey@3 77 }

mercurial