Merge

Tue, 14 May 2019 15:04:47 +0100

author
andrew
date
Tue, 14 May 2019 15:04:47 +0100
changeset 9672
20dd618188ce
parent 9670
884a9feb3bb8
parent 9671
e86bc9786d83
child 9673
7cbcb271bad7

Merge

     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/runtime/jni/CallWithJNIWeak/CallWithJNIWeak.c	Tue May 14 15:04:47 2019 +0100
     1.3 @@ -0,0 +1,142 @@
     1.4 +/*
     1.5 + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +#include <jni.h>
    1.28 +
    1.29 +/*
    1.30 + * Class:     CallWithJNIWeak
    1.31 + * Method:    testJNIFieldAccessors
    1.32 + * Signature: (LCallWithJNIWeak;)V
    1.33 + */
    1.34 +JNIEXPORT void JNICALL
    1.35 +Java_CallWithJNIWeak_testJNIFieldAccessors(JNIEnv *env, jclass clazz, jobject this) {
    1.36 +  // Make sure that we have a weak reference to the receiver
    1.37 +
    1.38 +  jweak self = (*env)->NewWeakGlobalRef(env, this);
    1.39 +
    1.40 +  jclass this_class = (*env)->GetObjectClass(env, self);
    1.41 +
    1.42 +  jclass exception = (*env)->FindClass(env, "java/lang/RuntimeException");
    1.43 +
    1.44 +  jfieldID id_i = (*env)->GetFieldID(env, this_class, "i", "I");
    1.45 +  jfieldID id_j = (*env)->GetFieldID(env, this_class, "j", "J");
    1.46 +  jfieldID id_z = (*env)->GetFieldID(env, this_class, "z", "Z");
    1.47 +  jfieldID id_c = (*env)->GetFieldID(env, this_class, "c", "C");
    1.48 +  jfieldID id_s = (*env)->GetFieldID(env, this_class, "s", "S");
    1.49 +  jfieldID id_f = (*env)->GetFieldID(env, this_class, "f", "F");
    1.50 +  jfieldID id_d = (*env)->GetFieldID(env, this_class, "d", "D");
    1.51 +  jfieldID id_l = (*env)->GetFieldID(env, this_class, "l", "Ljava/lang/Object;");
    1.52 +  jvalue v;
    1.53 +
    1.54 +#define CHECK(variable, expected)                                   \
    1.55 +  do {                                                              \
    1.56 +    if ((variable) != (expected)) {                                 \
    1.57 +      (*env)->ThrowNew(env, exception,  #variable" != " #expected); \
    1.58 +      return;                                                       \
    1.59 +    }                                                               \
    1.60 +  } while(0)
    1.61 +
    1.62 +  // The values checked below must be kept in sync with the Java source file.
    1.63 +
    1.64 +  v.i = (*env)->GetIntField(env, self, id_i);
    1.65 +  CHECK(v.i, 1);
    1.66 +
    1.67 +  v.j = (*env)->GetLongField(env, self, id_j);
    1.68 +  CHECK(v.j, 2);
    1.69 +
    1.70 +  v.z = (*env)->GetBooleanField(env, self, id_z);
    1.71 +  CHECK(v.z, JNI_TRUE);
    1.72 +
    1.73 +  v.c = (*env)->GetCharField(env, self, id_c);
    1.74 +  CHECK(v.c, 'a');
    1.75 +
    1.76 +  v.s = (*env)->GetShortField(env, self, id_s);
    1.77 +  CHECK(v.s, 3);
    1.78 +
    1.79 +  v.f = (*env)->GetFloatField(env, self, id_f);
    1.80 +  CHECK(v.f, 1.0f);
    1.81 +
    1.82 +  v.d = (*env)->GetDoubleField(env, self, id_d);
    1.83 +  CHECK(v.d, 2.0);
    1.84 +
    1.85 +#undef CHECK
    1.86 +
    1.87 +  v.l = (*env)->GetObjectField(env, self, id_l);
    1.88 +  if (v.l == NULL) {
    1.89 +    (*env)->ThrowNew(env, exception, "Object field was null");
    1.90 +    return;
    1.91 +  }
    1.92 +  {
    1.93 +    jclass clz = (*env)->GetObjectClass(env, v.l);
    1.94 +    if (!(*env)->IsSameObject(env, clazz, clz)) {
    1.95 +      (*env)->ThrowNew(env, exception, "Bad object class");
    1.96 +    }
    1.97 +  }
    1.98 +
    1.99 +  (*env)->DeleteWeakGlobalRef(env, self);
   1.100 +}
   1.101 +
   1.102 +/*
   1.103 + * Class:     CallWithJNIWeak
   1.104 + * Method:    runTests
   1.105 + * Signature: (LCallWithJNIWeak;)V
   1.106 + */
   1.107 +JNIEXPORT void JNICALL
   1.108 +Java_CallWithJNIWeak_runTests(JNIEnv *env, jclass clazz, jobject this) {
   1.109 +  jweak that = (*env)->NewWeakGlobalRef(env, this);
   1.110 +  {
   1.111 +    jmethodID method = (*env)->GetStaticMethodID(env,
   1.112 +                                                 clazz, "testJNIFieldAccessors", "(LCallWithJNIWeak;)V");
   1.113 +    (*env)->CallStaticVoidMethod(env, clazz, method, that);
   1.114 +    if ((*env)->ExceptionCheck(env)) {
   1.115 +      return;
   1.116 +    }
   1.117 +  }
   1.118 +
   1.119 +  {
   1.120 +    jmethodID method = (*env)->GetMethodID(env, clazz, "weakReceiverTest", "()V");
   1.121 +    (*env)->CallVoidMethod(env, that, method);
   1.122 +    if ((*env)->ExceptionCheck(env)) {
   1.123 +      return;
   1.124 +    }
   1.125 +  }
   1.126 +
   1.127 +  {
   1.128 +    jmethodID method = (*env)->GetMethodID(env, clazz, "synchonizedWeakReceiverTest", "()V");
   1.129 +    (*env)->CallVoidMethod(env, that, method);
   1.130 +    if ((*env)->ExceptionCheck(env)) {
   1.131 +      return;
   1.132 +    }
   1.133 +  }
   1.134 +  (*env)->DeleteWeakGlobalRef(env, that);
   1.135 +}
   1.136 +
   1.137 +/*
   1.138 + * Class:     CallWithJNIWeak
   1.139 + * Method:    weakReceiverTest0
   1.140 + * Signature: ()V
   1.141 + */
   1.142 +JNIEXPORT void JNICALL
   1.143 +Java_CallWithJNIWeak_weakReceiverTest0(JNIEnv *env, jobject obj) {
   1.144 +  (*env)->GetObjectClass(env, obj);
   1.145 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/runtime/jni/CallWithJNIWeak/CallWithJNIWeak.java	Tue May 14 15:04:47 2019 +0100
     2.3 @@ -0,0 +1,63 @@
     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 CallWithJNIWeak {
    2.28 +    static {
    2.29 +        System.loadLibrary("CallWithJNIWeak");
    2.30 +    }
    2.31 +
    2.32 +    private static native void testJNIFieldAccessors(CallWithJNIWeak o);
    2.33 +
    2.34 +    // The field initializations must be kept in sync with the JNI code
    2.35 +    // which reads verifies the values of these fields.
    2.36 +    private int i = 1;
    2.37 +    private long j = 2;
    2.38 +    private boolean z = true;
    2.39 +    private char c = 'a';
    2.40 +    private short s = 3;
    2.41 +    private float f = 1.0f;
    2.42 +    private double d = 2.0;
    2.43 +    private Object l;
    2.44 +
    2.45 +    private CallWithJNIWeak() {
    2.46 +        this.l = this;
    2.47 +    }
    2.48 +
    2.49 +    private native void weakReceiverTest0();
    2.50 +    private void weakReceiverTest() {
    2.51 +        weakReceiverTest0();
    2.52 +    }
    2.53 +
    2.54 +    private synchronized void synchonizedWeakReceiverTest() {
    2.55 +        this.notifyAll();
    2.56 +    }
    2.57 +
    2.58 +    private static native void runTests(CallWithJNIWeak o);
    2.59 +
    2.60 +    public static void main(String[] args) {
    2.61 +        CallWithJNIWeak w = new CallWithJNIWeak();
    2.62 +        for (int i = 0; i < 20000; i++) {
    2.63 +            runTests(w);
    2.64 +        }
    2.65 +    }
    2.66 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/runtime/jni/CallWithJNIWeak/test.sh	Tue May 14 15:04:47 2019 +0100
     3.3 @@ -0,0 +1,93 @@
     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) 2011 SAP AG.  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 test.sh
    3.31 +## @bug 8166188
    3.32 +## @requires vm.opt.ExplicitGCInvokesConcurrent != true
    3.33 +## @summary Test call of native function with JNI weak global ref.
    3.34 +## @run shell test.sh
    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 +OS=`uname -s`
    3.47 +echo "Testing on " $OS
    3.48 +case "$OS" in
    3.49 +  Linux)
    3.50 +    cc_cmd=`which gcc`
    3.51 +    if [ "x$cc_cmd" == "x" ]; then
    3.52 +        echo "WARNING: gcc not found. Cannot execute test." 2>&1
    3.53 +        exit 0;
    3.54 +    fi
    3.55 +    ;;
    3.56 +  Solaris)
    3.57 +    cc_cmd=`which cc`
    3.58 +    if [ "x$cc_cmd" == "x" ]; then
    3.59 +        echo "WARNING: cc not found. Cannot execute test." 2>&1
    3.60 +        exit 0;
    3.61 +    fi
    3.62 +    ;;
    3.63 +  *)
    3.64 +    echo "Test passed; only valid for Linux and Solaris"
    3.65 +    exit 0;
    3.66 +    ;;
    3.67 +esac
    3.68 +
    3.69 +THIS_DIR=.
    3.70 +
    3.71 +cp ${TESTSRC}${FS}*.java ${THIS_DIR}
    3.72 +${TESTJAVA}${FS}bin${FS}javac *.java
    3.73 +
    3.74 +$cc_cmd -fPIC -shared -o libCallWithJNIWeak.so \
    3.75 +    -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux \
    3.76 +    ${TESTSRC}${FS}CallWithJNIWeak.c
    3.77 +
    3.78 +LD_LIBRARY_PATH=${THIS_DIR}
    3.79 +echo   LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
    3.80 +export LD_LIBRARY_PATH
    3.81 +
    3.82 +echo
    3.83 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xint CallWithJNIWeak
    3.84 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xint CallWithJNIWeak
    3.85 +JAVA_RETVAL=$?
    3.86 +
    3.87 +if [ "$JAVA_RETVAL" == "0" ]
    3.88 +then
    3.89 +  echo
    3.90 +  echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xcomp CallWithJNIWeak
    3.91 +  ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xcomp CallWithJNIWeak
    3.92 +
    3.93 +  JAVA_RETVAL=$?
    3.94 +fi
    3.95 +
    3.96 +exit $JAVA_RETVAL
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/runtime/jni/ReturnJNIWeak/ReturnJNIWeak.c	Tue May 14 15:04:47 2019 +0100
     4.3 @@ -0,0 +1,52 @@
     4.4 +/*
     4.5 + * Copyright (c) 2017, 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 + * Native support for ReturnJNIWeak test.
    4.29 + */
    4.30 +
    4.31 +#include "jni.h"
    4.32 +
    4.33 +static jweak registered = NULL;
    4.34 +
    4.35 +JNIEXPORT void JNICALL
    4.36 +Java_ReturnJNIWeak_registerObject(JNIEnv* env,
    4.37 +                                  jclass jclazz,
    4.38 +                                  jobject value) {
    4.39 +  // assert registered == NULL
    4.40 +  registered = (*env)->NewWeakGlobalRef(env, value);
    4.41 +}
    4.42 +
    4.43 +JNIEXPORT void JNICALL
    4.44 +Java_ReturnJNIWeak_unregisterObject(JNIEnv* env, jclass jclazz) {
    4.45 +  if (registered != NULL) {
    4.46 +    (*env)->DeleteWeakGlobalRef(env, registered);
    4.47 +    registered = NULL;
    4.48 +  }
    4.49 +}
    4.50 +
    4.51 +JNIEXPORT jobject JNICALL
    4.52 +Java_ReturnJNIWeak_getObject(JNIEnv* env, jclass jclazz) {
    4.53 +  // assert registered != NULL
    4.54 +  return registered;
    4.55 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/runtime/jni/ReturnJNIWeak/ReturnJNIWeak.java	Tue May 14 15:04:47 2019 +0100
     5.3 @@ -0,0 +1,122 @@
     5.4 +/*
     5.5 + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +public final class ReturnJNIWeak {
    5.28 +    static {
    5.29 +        System.loadLibrary("ReturnJNIWeak");
    5.30 +    }
    5.31 +
    5.32 +    private static final class TestObject {
    5.33 +        public final int value;
    5.34 +
    5.35 +        public TestObject(int value) {
    5.36 +            this.value = value;
    5.37 +        }
    5.38 +    }
    5.39 +
    5.40 +    private static volatile TestObject testObject = null;
    5.41 +
    5.42 +    private static native void registerObject(Object o);
    5.43 +    private static native void unregisterObject();
    5.44 +    private static native Object getObject();
    5.45 +
    5.46 +    // Create the test object and record it both strongly and weakly.
    5.47 +    private static void remember(int value) {
    5.48 +        TestObject o = new TestObject(value);
    5.49 +        registerObject(o);
    5.50 +        testObject = o;
    5.51 +    }
    5.52 +
    5.53 +    // Remove both strong and weak references to the current test object.
    5.54 +    private static void forget() {
    5.55 +        unregisterObject();
    5.56 +        testObject = null;
    5.57 +    }
    5.58 +
    5.59 +    // Verify the weakly recorded object
    5.60 +    private static void checkValue(int value) throws Exception {
    5.61 +        Object o = getObject();
    5.62 +        if (o == null) {
    5.63 +            throw new RuntimeException("Weak reference unexpectedly null");
    5.64 +        }
    5.65 +        TestObject t = (TestObject)o;
    5.66 +        if (t.value != value) {
    5.67 +            throw new RuntimeException("Incorrect value");
    5.68 +        }
    5.69 +    }
    5.70 +
    5.71 +    // Verify we can create a weak reference and get it back.
    5.72 +    private static void testSanity() throws Exception {
    5.73 +        System.out.println("running testSanity");
    5.74 +        int value = 5;
    5.75 +        try {
    5.76 +            remember(value);
    5.77 +            checkValue(value);
    5.78 +        } finally {
    5.79 +            forget();
    5.80 +        }
    5.81 +    }
    5.82 +
    5.83 +    // Verify weak ref value survives across collection if strong ref exists.
    5.84 +    private static void testSurvival() throws Exception {
    5.85 +        System.out.println("running testSurvival");
    5.86 +        int value = 10;
    5.87 +        try {
    5.88 +            remember(value);
    5.89 +            checkValue(value);
    5.90 +            System.gc();
    5.91 +            // Verify weak ref still has expected value.
    5.92 +            checkValue(value);
    5.93 +        } finally {
    5.94 +            forget();
    5.95 +        }
    5.96 +    }
    5.97 +
    5.98 +    // Verify weak ref cleared if no strong ref exists.
    5.99 +    private static void testClear() throws Exception {
   5.100 +        System.out.println("running testClear");
   5.101 +        int value = 15;
   5.102 +        try {
   5.103 +            remember(value);
   5.104 +            checkValue(value);
   5.105 +            // Verify still good.
   5.106 +            checkValue(value);
   5.107 +            // Drop reference.
   5.108 +            testObject = null;
   5.109 +            System.gc();
   5.110 +            // Verify weak ref cleared as expected.
   5.111 +            Object recorded = getObject();
   5.112 +            if (recorded != null) {
   5.113 +                throw new RuntimeException("expected clear");
   5.114 +            }
   5.115 +        } finally {
   5.116 +            forget();
   5.117 +        }
   5.118 +    }
   5.119 +
   5.120 +    public static void main(String[] args) throws Exception {
   5.121 +        testSanity();
   5.122 +        testSurvival();
   5.123 +        testClear();
   5.124 +    }
   5.125 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/runtime/jni/ReturnJNIWeak/test.sh	Tue May 14 15:04:47 2019 +0100
     6.3 @@ -0,0 +1,93 @@
     6.4 +#!/bin/sh
     6.5 +
     6.6 +#
     6.7 +#  Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
     6.8 +#  Copyright (c) 2011 SAP AG.  All Rights Reserved.
     6.9 +#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    6.10 +#
    6.11 +#  This code is free software; you can redistribute it and/or modify it
    6.12 +#  under the terms of the GNU General Public License version 2 only, as
    6.13 +#  published by the Free Software Foundation.
    6.14 +#
    6.15 +#  This code is distributed in the hope that it will be useful, but WITHOUT
    6.16 +#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.17 +#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.18 +#  version 2 for more details (a copy is included in the LICENSE file that
    6.19 +#  accompanied this code).
    6.20 +#
    6.21 +#  You should have received a copy of the GNU General Public License version
    6.22 +#  2 along with this work; if not, write to the Free Software Foundation,
    6.23 +#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.24 +#
    6.25 +#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.26 +#  or visit www.oracle.com if you need additional information or have any
    6.27 +#  questions.
    6.28 +#
    6.29 +
    6.30 +## @test test.sh
    6.31 +## @bug 8166188
    6.32 +## @requires vm.opt.ExplicitGCInvokesConcurrent != true
    6.33 +## @summary Test return of JNI weak global refs from native calls.
    6.34 +## @run shell test.sh
    6.35 +
    6.36 +if [ "${TESTSRC}" = "" ]
    6.37 +then
    6.38 +  TESTSRC=${PWD}
    6.39 +  echo "TESTSRC not set.  Using "${TESTSRC}" as default"
    6.40 +fi
    6.41 +echo "TESTSRC=${TESTSRC}"
    6.42 +## Adding common setup Variables for running shell tests.
    6.43 +. ${TESTSRC}/../../../test_env.sh
    6.44 +
    6.45 +# set platform-dependent variables
    6.46 +OS=`uname -s`
    6.47 +echo "Testing on " $OS
    6.48 +case "$OS" in
    6.49 +  Linux)
    6.50 +    cc_cmd=`which gcc`
    6.51 +    if [ "x$cc_cmd" == "x" ]; then
    6.52 +        echo "WARNING: gcc not found. Cannot execute test." 2>&1
    6.53 +        exit 0;
    6.54 +    fi
    6.55 +    ;;
    6.56 +  Solaris)
    6.57 +    cc_cmd=`which cc`
    6.58 +    if [ "x$cc_cmd" == "x" ]; then
    6.59 +        echo "WARNING: cc not found. Cannot execute test." 2>&1
    6.60 +        exit 0;
    6.61 +    fi
    6.62 +    ;;
    6.63 +  *)
    6.64 +    echo "Test passed; only valid for Linux and Solaris"
    6.65 +    exit 0;
    6.66 +    ;;
    6.67 +esac
    6.68 +
    6.69 +THIS_DIR=.
    6.70 +
    6.71 +cp ${TESTSRC}${FS}*.java ${THIS_DIR}
    6.72 +${TESTJAVA}${FS}bin${FS}javac *.java
    6.73 +
    6.74 +$cc_cmd -fPIC -shared -o libReturnJNIWeak.so \
    6.75 +    -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux \
    6.76 +    ${TESTSRC}${FS}ReturnJNIWeak.c
    6.77 +
    6.78 +LD_LIBRARY_PATH=${THIS_DIR}
    6.79 +echo   LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
    6.80 +export LD_LIBRARY_PATH
    6.81 +
    6.82 +echo
    6.83 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xint ReturnJNIWeak
    6.84 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xint ReturnJNIWeak
    6.85 +JAVA_RETVAL=$?
    6.86 +
    6.87 +if [ "$JAVA_RETVAL" == "0" ]
    6.88 +then
    6.89 +  echo
    6.90 +  echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xcomp ReturnJNIWeak
    6.91 +  ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} -Xcomp ReturnJNIWeak
    6.92 +
    6.93 +  JAVA_RETVAL=$?
    6.94 +fi
    6.95 +
    6.96 +exit $JAVA_RETVAL

mercurial