8019811: Static calls - self referential functions needed a return type conversion if they were specialized, as they can't use the same mechanism as indy calls

Wed, 03 Jul 2013 15:46:03 +0200

author
lagergren
date
Wed, 03 Jul 2013 15:46:03 +0200
changeset 407
961cffae0828
parent 406
eb1437d16ab4
child 408
fcb484c43348
child 412
be2087629eb9

8019811: Static calls - self referential functions needed a return type conversion if they were specialized, as they can't use the same mechanism as indy calls
Reviewed-by: sundar, jlaskey

src/jdk/nashorn/internal/codegen/CodeGenerator.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8016667.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8019808.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8019810.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8019810.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/JDK-8019811.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8019817.js file | annotate | diff | comparison | revisions
test/script/currently-failing/JDK-8019809.js file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Wed Jul 03 17:26:31 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Wed Jul 03 15:46:03 2013 +0200
     1.3 @@ -578,6 +578,7 @@
     1.4          final Node         function        = callNode.getFunction();
     1.5          final Block        currentBlock    = lc.getCurrentBlock();
     1.6          final CodeGeneratorLexicalContext codegenLexicalContext = lc;
     1.7 +        final Type         callNodeType    = callNode.getType();
     1.8  
     1.9          function.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
    1.10  
    1.11 @@ -593,7 +594,7 @@
    1.12                  }
    1.13                  loadArgs(args);
    1.14                  final Type[] paramTypes = method.getTypesFromStack(args.size());
    1.15 -                final SharedScopeCall scopeCall = codegenLexicalContext.getScopeCall(unit, symbol, identNode.getType(), callNode.getType(), paramTypes, scopeCallFlags);
    1.16 +                final SharedScopeCall scopeCall = codegenLexicalContext.getScopeCall(unit, symbol, identNode.getType(), callNodeType, paramTypes, scopeCallFlags);
    1.17                  return scopeCall.generateInvoke(method);
    1.18              }
    1.19  
    1.20 @@ -602,7 +603,7 @@
    1.21                  method.convert(Type.OBJECT); // foo() makes no sense if foo == 3
    1.22                  // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly.
    1.23                  method.loadNull(); //the 'this'
    1.24 -                method.dynamicCall(callNode.getType(), 2 + loadArgs(args), flags);
    1.25 +                method.dynamicCall(callNodeType, 2 + loadArgs(args), flags);
    1.26              }
    1.27  
    1.28              private void evalCall(final IdentNode node, final int flags) {
    1.29 @@ -634,14 +635,14 @@
    1.30  
    1.31                  // direct call to Global.directEval
    1.32                  globalDirectEval();
    1.33 -                method.convert(callNode.getType());
    1.34 +                method.convert(callNodeType);
    1.35                  method._goto(eval_done);
    1.36  
    1.37                  method.label(not_eval);
    1.38                  // This is some scope 'eval' or global eval replaced by user
    1.39                  // but not the built-in ECMAScript 'eval' function call
    1.40                  method.loadNull();
    1.41 -                method.dynamicCall(callNode.getType(), 2 + loadArgs(args), flags);
    1.42 +                method.dynamicCall(callNodeType, 2 + loadArgs(args), flags);
    1.43  
    1.44                  method.label(eval_done);
    1.45              }
    1.46 @@ -666,7 +667,7 @@
    1.47                      } else {
    1.48                          sharedScopeCall(node, flags);
    1.49                      }
    1.50 -                    assert method.peekType().equals(callNode.getType()) : method.peekType() + "!=" + callNode.getType();
    1.51 +                    assert method.peekType().equals(callNodeType) : method.peekType() + "!=" + callNode.getType();
    1.52                  } else {
    1.53                      enterDefault(node);
    1.54                  }
    1.55 @@ -681,8 +682,8 @@
    1.56                  method.dup();
    1.57                  method.dynamicGet(node.getType(), node.getProperty().getName(), getCallSiteFlags(), true);
    1.58                  method.swap();
    1.59 -                method.dynamicCall(callNode.getType(), 2 + loadArgs(args), getCallSiteFlags());
    1.60 -                assert method.peekType().equals(callNode.getType());
    1.61 +                method.dynamicCall(callNodeType, 2 + loadArgs(args), getCallSiteFlags());
    1.62 +                assert method.peekType().equals(callNodeType);
    1.63  
    1.64                  return false;
    1.65              }
    1.66 @@ -707,6 +708,7 @@
    1.67                  assert callee.getCompileUnit() != null : "no compile unit for " + callee.getName() + " " + Debug.id(callee) + " " + callNode;
    1.68                  method.invokestatic(callee.getCompileUnit().getUnitClassName(), callee.getName(), signature);
    1.69                  assert method.peekType().equals(callee.getReturnType()) : method.peekType() + " != " + callee.getReturnType();
    1.70 +                method.convert(callNodeType);
    1.71                  return false;
    1.72              }
    1.73  
    1.74 @@ -722,7 +724,7 @@
    1.75                  }
    1.76                  method.dynamicGetIndex(node.getType(), getCallSiteFlags(), true);
    1.77                  method.swap();
    1.78 -                method.dynamicCall(callNode.getType(), 2 + loadArgs(args), getCallSiteFlags());
    1.79 +                method.dynamicCall(callNodeType, 2 + loadArgs(args), getCallSiteFlags());
    1.80                  assert method.peekType().equals(callNode.getType());
    1.81  
    1.82                  return false;
    1.83 @@ -734,7 +736,7 @@
    1.84                  load(function);
    1.85                  method.convert(Type.OBJECT); //TODO, e.g. booleans can be used as functions
    1.86                  method.loadNull(); // ScriptFunction will figure out the correct this when it sees CALLSITE_SCOPE
    1.87 -                method.dynamicCall(callNode.getType(), 2 + loadArgs(args), getCallSiteFlags() | CALLSITE_SCOPE);
    1.88 +                method.dynamicCall(callNodeType, 2 + loadArgs(args), getCallSiteFlags() | CALLSITE_SCOPE);
    1.89                  assert method.peekType().equals(callNode.getType());
    1.90  
    1.91                  return false;
     2.1 --- a/test/script/basic/JDK-8016667.js	Wed Jul 03 17:26:31 2013 +0530
     2.2 +++ b/test/script/basic/JDK-8016667.js	Wed Jul 03 15:46:03 2013 +0200
     2.3 @@ -32,3 +32,23 @@
     2.4      var friends = 1;
     2.5      (joe = friends) == null;
     2.6  } 
     2.7 +
     2.8 +//JDK-8019476 duplicate case of this
     2.9 +Function("with(\nnull == (this % {}))( /x/g );"); 
    2.10 +
    2.11 +function f() {
    2.12 +    with(null == (this % {}))(/x/g);
    2.13 +}
    2.14 +
    2.15 +Function("return (null != [,,] <= this);"); 
    2.16 +
    2.17 +function f2() {
    2.18 +    return (null != [,,] <= this);
    2.19 +}
    2.20 +
    2.21 +Function("/*infloop*/L:for(var x; ([+(function (window)[,,])(function(q) { return q; }, -0)].some(new Function)); [11,12,13,14].some) {/*infloop*/do {;return this; } while(x); }"); 
    2.22 +
    2.23 +function f3() {
    2.24 +    /*infloop*/L:for(var x; ([+(function (window)[,,])(function(q) { return q; }, -0)].some(new Function)); [11,12,13,14].some) {/*infloop*/do {;return this; } while(x); }
    2.25 +}
    2.26 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8019808.js	Wed Jul 03 15:46:03 2013 +0200
     3.3 @@ -0,0 +1,39 @@
     3.4 +/*
     3.5 + * Copyright (c) 2010, 2013, 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-8019808: Switch on empty array breaks codegen
    3.29 + *
    3.30 + * @test
    3.31 + * @run
    3.32 + */
    3.33 +
    3.34 +Function("switch([]) { case 7: }"); 
    3.35 +
    3.36 +function f() {
    3.37 +    switch([]) {
    3.38 +    case 7:
    3.39 +    }
    3.40 +}
    3.41 +
    3.42 +f();
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/script/basic/JDK-8019810.js	Wed Jul 03 15:46:03 2013 +0200
     4.3 @@ -0,0 +1,36 @@
     4.4 +/*
     4.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + * 
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + * 
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + * 
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + * 
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +/**
    4.28 + * JDK-8019810: Assertion error in attr in function body
    4.29 + *
    4.30 + * @test
    4.31 + * @run
    4.32 + */
    4.33 +
    4.34 +Function("return (void ({ set each (x2)y }));");
    4.35 +
    4.36 +function f() {
    4.37 +    return (void ({ set each (x2)y }));
    4.38 +}
    4.39 +print(f());
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/script/basic/JDK-8019810.js.EXPECTED	Wed Jul 03 15:46:03 2013 +0200
     5.3 @@ -0,0 +1,1 @@
     5.4 +undefined
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/script/basic/JDK-8019811.js	Wed Jul 03 15:46:03 2013 +0200
     6.3 @@ -0,0 +1,47 @@
     6.4 +/*
     6.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + * 
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + * 
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + * 
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + * 
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +/**
    6.28 + * JDK-8019811: Number coercion for return values of static calls was broken
    6.29 + *
    6.30 + * @test
    6.31 + * @run
    6.32 + */
    6.33 +
    6.34 +function f(x) {
    6.35 +    var window = 17;
    6.36 +    return function (x) { 
    6.37 +	return true 
    6.38 +    } (x) >> window;
    6.39 +}
    6.40 +
    6.41 +Function("L:if((function x ()3)() + arguments++) {return; } else if (new gc()) while(((x2.prop = functional)) && 0){ }"); 
    6.42 +
    6.43 +Function("var x = x -= '' "); 
    6.44 +
    6.45 +Function("switch((Math.pow ? x = 1.2e3 : 3)) { default: return; }") 
    6.46 +
    6.47 +Function("x = 0.1, x\ntrue\n~this");
    6.48 +
    6.49 +Function("with((function (x)x2)() ^ this){return; }");
    6.50 + 
    6.51 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/script/basic/JDK-8019817.js	Wed Jul 03 15:46:03 2013 +0200
     7.3 @@ -0,0 +1,37 @@
     7.4 +/*
     7.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + * 
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + * 
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + * 
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + * 
    7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.23 + * or visit www.oracle.com if you need additional information or have any
    7.24 + * questions.
    7.25 + */
    7.26 +
    7.27 +/**
    7.28 + * JDK-8019817: More number coercion issues
    7.29 + *
    7.30 + * @test
    7.31 + * @run
    7.32 + */
    7.33 +var y = 17.17;
    7.34 +
    7.35 +Function("return y % function(q) { return q; }();"); 
    7.36 +
    7.37 +function f() {
    7.38 +    return y % function(q) { return q; }();
    7.39 +}
    7.40 +f();
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/script/currently-failing/JDK-8019809.js	Wed Jul 03 15:46:03 2013 +0200
     8.3 @@ -0,0 +1,37 @@
     8.4 +/*
     8.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + * 
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + * 
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + * 
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + * 
    8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 + * or visit www.oracle.com if you need additional information or have any
    8.24 + * questions.
    8.25 + */
    8.26 +
    8.27 +/**
    8.28 + * JDK-8019809: Break return combo that generates erroneous bytecode
    8.29 + *
    8.30 + * @test
    8.31 + * @run
    8.32 + */
    8.33 +
    8.34 +//Function("L: {break L;return; }"); 
    8.35 +
    8.36 +function f() {
    8.37 +    L: { break L; return; }
    8.38 +}
    8.39 +
    8.40 +f();

mercurial