8167409: Invalid value passed to critical JNI function

Thu, 27 Feb 2020 06:05:11 +0000

author
fyang
date
Thu, 27 Feb 2020 06:05:11 +0000
changeset 9844
6a809b1ac0a8
parent 9843
a6f289d66efe
child 9845
68172de2a0d7

8167409: Invalid value passed to critical JNI function
Summary: the tmp reg used to break the shuffling cycle (handled in ComputeMoveOrder) is set to 64 bit.
Reviewed-by: andrew

src/cpu/x86/vm/sharedRuntime_x86_64.cpp file | annotate | diff | comparison | revisions
test/compiler/criticalnatives/argumentcorruption/CheckLongArgs.java file | annotate | diff | comparison | revisions
test/compiler/criticalnatives/argumentcorruption/Test8167409.sh file | annotate | diff | comparison | revisions
test/compiler/criticalnatives/argumentcorruption/libCNCheckLongArgs.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Thu Feb 27 05:58:53 2020 +0000
     1.2 +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Thu Feb 27 06:05:11 2020 +0000
     1.3 @@ -2098,7 +2098,7 @@
     1.4    // critical natives they are offset down.
     1.5    GrowableArray<int> arg_order(2 * total_in_args);
     1.6    VMRegPair tmp_vmreg;
     1.7 -  tmp_vmreg.set1(rbx->as_VMReg());
     1.8 +  tmp_vmreg.set2(rbx->as_VMReg());
     1.9  
    1.10    if (!is_critical_native) {
    1.11      for (int i = total_in_args - 1, c_arg = total_c_args - 1; i >= 0; i--, c_arg--) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/criticalnatives/argumentcorruption/CheckLongArgs.java	Thu Feb 27 06:05:11 2020 +0000
     2.3 @@ -0,0 +1,54 @@
     2.4 +/*
     2.5 + * Copyright (c) 2017, 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 CheckLongArgs {
    2.28 +    static {
    2.29 +        System.loadLibrary("CNCheckLongArgs");
    2.30 +    }
    2.31 +    static native void m1(long a1, long a2, long a3, long a4,  long a5, long a6, long a7, long a8, byte[] result);
    2.32 +    static native void m2(long a1, int[] a2, long a3, int[] a4, long a5, int[] a6, long a7, int[] a8, long a9, byte[] result);
    2.33 +    public static void main(String args[]) throws Exception {
    2.34 +        test();
    2.35 +    }
    2.36 +    private static void test() throws Exception {
    2.37 +        int[] l1 = { 1111, 2222, 3333 };
    2.38 +        int[] l2 = { 4444, 5555, 6666 };
    2.39 +        int[] l3 = { 7777, 8888, 9999 };
    2.40 +        int[] l4 = { 1010, 2020, 3030 };
    2.41 +        byte[] result = { -1 };
    2.42 +        m1(1111111122222222L, 3333333344444444L, 5555555566666666L, 7777777788888888L, 9999999900000000L, 1212121234343434L,
    2.43 +           5656565678787878L, 9090909012121212L, result);
    2.44 +        check(result[0]);
    2.45 +        result[0] = -1;
    2.46 +        m2(1111111122222222L, l1, 3333333344444444L, l2, 5555555566666666L, l3, 7777777788888888L, l4, 9999999900000000L, result);
    2.47 +        check(result[0]);
    2.48 +    }
    2.49 +    private static void check(byte result) throws Exception {
    2.50 +        if (result != 2) {
    2.51 +            if (result == 1) {
    2.52 +              throw new Exception("critical native arguments mismatch");
    2.53 +            }
    2.54 +            throw new Exception("critical native lookup failed");
    2.55 +        }
    2.56 +    }
    2.57 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/compiler/criticalnatives/argumentcorruption/Test8167409.sh	Thu Feb 27 06:05:11 2020 +0000
     3.3 @@ -0,0 +1,83 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +#
     3.7 +#  Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
     3.8 +#  Copyright (c) 2019 Huawei Technologies Co. LTD.  All Rights Reserved.
     3.9 +#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    3.10 +#
    3.11 +#  This code is free software; you can redistribute it and/or modify it
    3.12 +#  under the terms of the GNU General Public License version 2 only, as
    3.13 +#  published by the Free Software Foundation.
    3.14 +#
    3.15 +#  This code is distributed in the hope that it will be useful, but WITHOUT
    3.16 +#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.17 +#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.18 +#  version 2 for more details (a copy is included in the LICENSE file that
    3.19 +#  accompanied this code).
    3.20 +#
    3.21 +#  You should have received a copy of the GNU General Public License version
    3.22 +#  2 along with this work; if not, write to the Free Software Foundation,
    3.23 +#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.24 +#
    3.25 +#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.26 +#  or visit www.oracle.com if you need additional information or have any
    3.27 +#  questions.
    3.28 +#
    3.29 +
    3.30 +## @test Test8167409.sh
    3.31 +## @bug 8167409
    3.32 +## @summary Invalid value passed to critical JNI function
    3.33 +## @run shell Test8167409.sh
    3.34 +
    3.35 +if [ "${TESTSRC}" = "" ]
    3.36 +then
    3.37 +  TESTSRC=${PWD}
    3.38 +  echo "TESTSRC not set.  Using "${TESTSRC}" as default"
    3.39 +fi
    3.40 +echo "TESTSRC=${TESTSRC}"
    3.41 +## Adding common setup Variables for running shell tests.
    3.42 +. ${TESTSRC}/../../../test_env.sh
    3.43 +
    3.44 +# set platform-dependent variables
    3.45 +OS=`uname -s`
    3.46 +echo "Testing on " $OS
    3.47 +case "$OS" in
    3.48 +  Linux)
    3.49 +    cc_cmd=`which gcc`
    3.50 +    if [ "x$cc_cmd" == "x" ]; then
    3.51 +        echo "WARNING: gcc not found. Cannot execute test." 2>&1
    3.52 +        exit 0;
    3.53 +    fi
    3.54 +    ;;
    3.55 +  Solaris)
    3.56 +    cc_cmd=`which cc`
    3.57 +    if [ "x$cc_cmd" == "x" ]; then
    3.58 +        echo "WARNING: cc not found. Cannot execute test." 2>&1
    3.59 +        exit 0;
    3.60 +    fi
    3.61 +    ;;
    3.62 +  *)
    3.63 +    echo "Test passed; only valid for Linux and Solaris"
    3.64 +    exit 0;
    3.65 +    ;;
    3.66 +esac
    3.67 +
    3.68 +THIS_DIR=.
    3.69 +
    3.70 +cp ${TESTSRC}${FS}*.java ${THIS_DIR}
    3.71 +${TESTJAVA}${FS}bin${FS}javac *.java
    3.72 +
    3.73 +$cc_cmd -fPIC -shared -o libCNCheckLongArgs.so \
    3.74 +    -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux \
    3.75 +    ${TESTSRC}${FS}libCNCheckLongArgs.c
    3.76 +
    3.77 +LD_LIBRARY_PATH=${THIS_DIR}
    3.78 +echo   LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
    3.79 +export LD_LIBRARY_PATH
    3.80 +
    3.81 +echo
    3.82 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xcomp -XX:+CriticalJNINatives CheckLongArgs
    3.83 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xcomp -XX:+CriticalJNINatives CheckLongArgs
    3.84 +JAVA_RETVAL=$?
    3.85 +
    3.86 +exit $JAVA_RETVAL
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/compiler/criticalnatives/argumentcorruption/libCNCheckLongArgs.c	Thu Feb 27 06:05:11 2020 +0000
     4.3 @@ -0,0 +1,30 @@
     4.4 +#include "jni.h"
     4.5 +JNIEXPORT void JNICALL JavaCritical_CheckLongArgs_m1
     4.6 +  (jlong a1, jlong a2, jlong a3, jlong a4, jlong a5, jlong a6, jlong a7, jlong a8,jint result_length,jbyte* result) {
     4.7 +
     4.8 +  if (a1 != 1111111122222222LL || a2 != 3333333344444444LL || a3 != 5555555566666666LL || a4 != 7777777788888888LL ||
     4.9 +      a5 != 9999999900000000LL || a6 != 1212121234343434LL || a7 != 5656565678787878LL || a8 != 9090909012121212LL ||
    4.10 +      result_length != 1 || result[0] != -1) {
    4.11 +    result[0] = 1;
    4.12 +  } else {
    4.13 +    result[0] = 2;
    4.14 +  }
    4.15 +}
    4.16 +
    4.17 +JNIEXPORT void JNICALL JavaCritical_CheckLongArgs_m2
    4.18 +  (jlong a1, jint a2_length, jint* a2, jlong a3, jint a4_length, jint* a4, jlong a5, jint a6_length, jint* a6, jlong a7,
    4.19 +   jint a8_length, jint* a8, jlong a9, jint result_length, jbyte* result) {
    4.20 +  if (a1 != 1111111122222222LL || a2_length != 3 || a2[0] != 1111 || a3 != 3333333344444444LL || a4_length != 3 || a4[0] != 4444 ||
    4.21 +      a5 != 5555555566666666LL || a6_length != 3 || a6[0] != 7777 || a7 != 7777777788888888LL || a8_length != 3 || a8[0] != 1010 || a9 != 9999999900000000LL ||
    4.22 +      result_length != 1 || result[0] != -1) {
    4.23 +    result[0] = 1;
    4.24 +  } else {
    4.25 +    result[0] = 2;
    4.26 +  }
    4.27 +}
    4.28 +
    4.29 +JNIEXPORT void JNICALL Java_CheckLongArgs_m1
    4.30 +  (JNIEnv * env, jclass jclazz, jlong a3, jlong a4, jlong a5, jlong a6, jlong a7, jlong a8, jlong a9, jlong a10, jbyteArray result) {}
    4.31 +
    4.32 +JNIEXPORT void JNICALL Java_CheckLongArgs_m2
    4.33 +  (JNIEnv * env, jclass jclazz, jlong a3, jintArray a4, jlong a5, jintArray a6, jlong a7, jintArray a8, jlong a9, jintArray a10, jlong a11, jbyteArray result) {}

mercurial