8016667: Wrong bytecode when testing/setting due to null check shortcut checking against primitive too
authorlagergren
Tue, 02 Jul 2013 13:50:19 +0200
changeset 18631 537b279999e5
parent 18630 48e3dc4bf0f6
child 18632 93017277615e
child 18633 c2138d47b2c6
8016667: Wrong bytecode when testing/setting due to null check shortcut checking against primitive too Reviewed-by: jlaskey, sundar
nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
nashorn/test/script/basic/JDK-8016667.js
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 07:45:16 2013 -0300
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 13:50:19 2013 +0200
@@ -1462,7 +1462,9 @@
             rhs = tmp;
         }
 
-        if (isNullLiteral(rhs)) {
+        // this is a null literal check, so if there is implicit coercion
+        // involved like {D}x=null, we will fail - this is very rare
+        if (isNullLiteral(rhs) && lhs.getType().isObject()) {
             final Label trueLabel  = new Label("trueLabel");
             final Label falseLabel = new Label("falseLabel");
             final Label endLabel   = new Label("end");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8016667.js	Tue Jul 02 13:50:19 2013 +0200
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Regression test for erroneous shortcut optimization for object null checks
+ *
+ * @test
+ * @run
+ */
+
+function toto() {
+    var friends = 1;
+    (joe = friends) == null;
+}