8066236: RuntimeNode forces copy creation on visitation

Wed, 10 Dec 2014 12:30:48 +0100

author
attila
date
Wed, 10 Dec 2014 12:30:48 +0100
changeset 1123
8cb808c0db80
parent 1122
bbbe34896bde
child 1124
0972880cbb97

8066236: RuntimeNode forces copy creation on visitation
Reviewed-by: hannesw, lagergren

src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/RuntimeNode.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8066236.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8066236.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java	Wed Dec 10 11:55:25 2014 +0100
     1.2 +++ b/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java	Wed Dec 10 12:30:48 2014 +0100
     1.3 @@ -93,6 +93,13 @@
     1.4   * variable to its widest used type after the join point. That would eliminate some widenings of undefined variables to
     1.5   * object, most notably those used only in loops. We need a full liveness analysis for that. Currently, we can establish
     1.6   * per-type liveness, which eliminates most of unwanted dead widenings.
     1.7 + * NOTE: the way this class is implemented, it actually processes the AST in two passes. The first pass is top-down and
     1.8 + * implemented in {@code enterXxx} methods. This pass does not mutate the AST (except for one occurrence, noted below),
     1.9 + * as being able to find relevant labels for control flow joins is sensitive to their reference identity, and mutated
    1.10 + * label-carrying nodes will create copies of their labels. A second bottom-up pass applying the changes is implemented
    1.11 + * in the separate visitor sitting in {@link #leaveFunctionNode(FunctionNode)}. This visitor will also instantiate new
    1.12 + * instances of the calculator to be run on nested functions (when not lazy compiling).
    1.13 + *
    1.14   */
    1.15  final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
    1.16  
     2.1 --- a/src/jdk/nashorn/internal/ir/RuntimeNode.java	Wed Dec 10 11:55:25 2014 +0100
     2.2 +++ b/src/jdk/nashorn/internal/ir/RuntimeNode.java	Wed Dec 10 12:30:48 2014 +0100
     2.3 @@ -27,7 +27,6 @@
     2.4  
     2.5  import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
     2.6  
     2.7 -import java.util.ArrayList;
     2.8  import java.util.Arrays;
     2.9  import java.util.Collections;
    2.10  import java.util.List;
    2.11 @@ -468,11 +467,7 @@
    2.12      @Override
    2.13      public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
    2.14          if (visitor.enterRuntimeNode(this)) {
    2.15 -            final List<Expression> newArgs = new ArrayList<>();
    2.16 -            for (final Node arg : args) {
    2.17 -                newArgs.add((Expression)arg.accept(visitor));
    2.18 -            }
    2.19 -            return visitor.leaveRuntimeNode(setArgs(newArgs));
    2.20 +            return visitor.leaveRuntimeNode(setArgs(Node.accept(visitor, args)));
    2.21          }
    2.22  
    2.23          return this;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8066236.js	Wed Dec 10 12:30:48 2014 +0100
     3.3 @@ -0,0 +1,46 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + * 
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + * 
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + * 
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + * 
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * JDK-8066236: RuntimeNode forces copy creation on visitation
    3.29 + *
    3.30 + * @test
    3.31 + * @run
    3.32 + */
    3.33 +
    3.34 +// Note: we're using Function("code") instead of (function(){ code }) so that
    3.35 +// we don't trigger parser API validation in JDK-8008448 tests. The test code
    3.36 +// encapsulated in functions below can't be correctly handled by the parser API
    3.37 +// currently, as it contains parser-generated REFERENCE_ERROR runtime nodes.
    3.38 +try {
    3.39 +    Function("L: {this = x;break L}")();
    3.40 +} catch (e) {
    3.41 +   print("threw ReferenceError: " + (e instanceof ReferenceError));
    3.42 +}
    3.43 +try {
    3.44 +    Function("L:with(this--)break L;")();
    3.45 +} catch (e) {
    3.46 +   print("threw ReferenceError: " + (e instanceof ReferenceError));
    3.47 +}
    3.48 +Function("L:with(Object in Object)break L;")();
    3.49 +print("SUCCESS");
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/script/basic/JDK-8066236.js.EXPECTED	Wed Dec 10 12:30:48 2014 +0100
     4.3 @@ -0,0 +1,3 @@
     4.4 +threw ReferenceError: true
     4.5 +threw ReferenceError: true
     4.6 +SUCCESS

mercurial