Mon, 29 Feb 2016 16:08:11 +0100
8148353: [linux-sparc] Crash in libawt.so on Linux SPARC
Summary: gcc expects clean 32 bit int in 64 bit register on function entry
Reviewed-by: kvn, dlong
1.1 --- a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp Thu Feb 11 12:42:12 2016 +0100 1.2 +++ b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp Mon Feb 29 16:08:11 2016 +0100 1.3 @@ -1326,9 +1326,12 @@ 1.4 } 1.5 } else if (dst.first()->is_stack()) { 1.6 // reg to stack 1.7 - __ st_ptr(src.first()->as_Register(), SP, reg2offset(dst.first()) + STACK_BIAS); 1.8 + // Some compilers (gcc) expect a clean 32 bit value on function entry 1.9 + __ signx(src.first()->as_Register(), L5); 1.10 + __ st_ptr(L5, SP, reg2offset(dst.first()) + STACK_BIAS); 1.11 } else { 1.12 - __ mov(src.first()->as_Register(), dst.first()->as_Register()); 1.13 + // Some compilers (gcc) expect a clean 32 bit value on function entry 1.14 + __ signx(src.first()->as_Register(), dst.first()->as_Register()); 1.15 } 1.16 } 1.17
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/native/TestDirtyInt.java Mon Feb 29 16:08:11 2016 +0100 2.3 @@ -0,0 +1,43 @@ 2.4 +/* 2.5 + * Copyright (c) 2016, 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 +public class TestDirtyInt { 2.28 + static { 2.29 + System.loadLibrary("TestDirtyInt"); 2.30 + } 2.31 + 2.32 + native static int test(int v); 2.33 + 2.34 + static int compiled(int v) { 2.35 + return test(v<<2); 2.36 + } 2.37 + 2.38 + static public void main(String[] args) { 2.39 + for (int i = 0; i < 20000; i++) { 2.40 + int res = compiled(Integer.MAX_VALUE); 2.41 + if (res != 0x42) { 2.42 + throw new RuntimeException("Test failed"); 2.43 + } 2.44 + } 2.45 + } 2.46 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/compiler/native/TestDirtyInt.sh Mon Feb 29 16:08:11 2016 +0100 3.3 @@ -0,0 +1,80 @@ 3.4 +#!/bin/sh 3.5 + 3.6 +# 3.7 +# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.9 +# 3.10 +# This code is free software; you can redistribute it and/or modify it 3.11 +# under the terms of the GNU General Public License version 2 only, as 3.12 +# published by the Free Software Foundation. 3.13 +# 3.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 3.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.17 +# version 2 for more details (a copy is included in the LICENSE file that 3.18 +# accompanied this code). 3.19 +# 3.20 +# You should have received a copy of the GNU General Public License version 3.21 +# 2 along with this work; if not, write to the Free Software Foundation, 3.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.23 +# 3.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.25 +# or visit www.oracle.com if you need additional information or have any 3.26 +# questions. 3.27 +# 3.28 + 3.29 +## 3.30 +## @test 3.31 +## @bug 8148353 3.32 +## @summary gcc on sparc expects clean 32 bit int in 64 bit register on function entry 3.33 +## @run shell/timeout=30 TestDirtyInt.sh 3.34 +## 3.35 + 3.36 +if [ "${TESTSRC}" = "" ] 3.37 +then 3.38 + TESTSRC=${PWD} 3.39 + echo "TESTSRC not set. Using "${TESTSRC}" as default" 3.40 +fi 3.41 +echo "TESTSRC=${TESTSRC}" 3.42 +## Adding common setup Variables for running shell tests. 3.43 +. ${TESTSRC}/../../test_env.sh 3.44 + 3.45 +# set platform-dependent variables 3.46 +if [ $VM_OS == "linux" -a $VM_CPU == "sparcv9" ]; then 3.47 + echo "Testing on linux-sparc" 3.48 + gcc_cmd=`which gcc` 3.49 + if [ "x$gcc_cmd" == "x" ]; then 3.50 + echo "WARNING: gcc not found. Cannot execute test." 2>&1 3.51 + exit 0; 3.52 + fi 3.53 +else 3.54 + echo "Test passed; only valid for linux-sparc" 3.55 + exit 0; 3.56 +fi 3.57 + 3.58 +THIS_DIR=. 3.59 + 3.60 +cp ${TESTSRC}${FS}*.java ${THIS_DIR} 3.61 +${TESTJAVA}${FS}bin${FS}javac *.java 3.62 + 3.63 +$gcc_cmd -O1 -DLINUX -fPIC -shared \ 3.64 + -o ${TESTSRC}${FS}libTestDirtyInt.so \ 3.65 + -I${TESTJAVA}${FS}include \ 3.66 + -I${TESTJAVA}${FS}include${FS}linux \ 3.67 + ${TESTSRC}${FS}libTestDirtyInt.c 3.68 + 3.69 +# run the java test in the background 3.70 +cmd="${TESTJAVA}${FS}bin${FS}java \ 3.71 + -Djava.library.path=${TESTSRC}${FS} TestDirtyInt" 3.72 + 3.73 +echo "$cmd" 3.74 +eval $cmd 3.75 + 3.76 +if [ $? = 0 ] 3.77 +then 3.78 + echo "Test Passed" 3.79 + exit 0 3.80 +fi 3.81 + 3.82 +echo "Test Failed" 3.83 +exit 1
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/compiler/native/libTestDirtyInt.c Mon Feb 29 16:08:11 2016 +0100 4.3 @@ -0,0 +1,33 @@ 4.4 +/* 4.5 + * Copyright (c) 2016, 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 +#include "jni.h" 4.28 +#include <stdio.h> 4.29 + 4.30 +static int array = 0x42; 4.31 + 4.32 +JNIEXPORT jint JNICALL Java_TestDirtyInt_test(JNIEnv* env, jclass jclazz, jint v) 4.33 +{ 4.34 + int* ptr = &array + v + 4; 4.35 + return *ptr; 4.36 +}