Wed, 02 Apr 2014 11:24:51 -0700
8039043: Implicit null check is in the wrong place in C1 -UseCompressedOops
Summary: Null check is placed in a wrong place when storing a null to an object field on x64 with compressed oops off
Reviewed-by: roland, vlivanov, kvn
src/cpu/x86/vm/c1_LIRAssembler_x86.cpp | file | annotate | diff | comparison | revisions | |
test/compiler/codegen/C1NullCheckOfNullStore.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Mon Mar 31 13:08:03 2014 -0700 1.2 +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Wed Apr 02 11:24:51 2014 -0700 1.3 @@ -801,7 +801,13 @@ 1.4 if (UseCompressedOops && !wide) { 1.5 __ movl(as_Address(addr), (int32_t)NULL_WORD); 1.6 } else { 1.7 +#ifdef _LP64 1.8 + __ xorptr(rscratch1, rscratch1); 1.9 + null_check_here = code_offset(); 1.10 + __ movptr(as_Address(addr), rscratch1); 1.11 +#else 1.12 __ movptr(as_Address(addr), NULL_WORD); 1.13 +#endif 1.14 } 1.15 } else { 1.16 if (is_literal_address(addr)) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/codegen/C1NullCheckOfNullStore.java Wed Apr 02 11:24:51 2014 -0700 2.3 @@ -0,0 +1,57 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8039043 2.30 + * @summary Null check is placed in a wrong place when storing a null to an object field on x64 with compressed oops off 2.31 + * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:CompileCommand=compileonly,C1NullCheckOfNullStore::test -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-UseCompressedOops C1NullCheckOfNullStore 2.32 + * 2.33 + */ 2.34 + 2.35 +public class C1NullCheckOfNullStore { 2.36 + private static class Foo { 2.37 + Object bar; 2.38 + } 2.39 + static private void test(Foo x) { 2.40 + x.bar = null; 2.41 + } 2.42 + static public void main(String args[]) { 2.43 + Foo x = new Foo(); 2.44 + for (int i = 0; i < 10000; i++) { 2.45 + test(x); 2.46 + } 2.47 + boolean gotNPE = false; 2.48 + try { 2.49 + for (int i = 0; i < 10000; i++) { 2.50 + test(null); 2.51 + } 2.52 + } 2.53 + catch(NullPointerException e) { 2.54 + gotNPE = true; 2.55 + } 2.56 + if (!gotNPE) { 2.57 + throw new Error("Expecting a NullPointerException"); 2.58 + } 2.59 + } 2.60 +}