1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8166188
  27  * @summary Test call of native function with JNI weak global ref.
  28  * @modules java.base
  29  * @run main/othervm/native CallWithJNIWeak
  30  */
  31 
  32 public class CallWithJNIWeak {
  33     static {
  34         System.loadLibrary("CallWithJNIWeak");
  35     }
  36 
  37     private static native void testJNIFieldAccessors(CallWithJNIWeak o);
  38 
  39     // The field initializations must be kept in sync with the JNI code
  40     // which reads verifies the values of these fields.
  41     private int i = 1;
  42     private long j = 2;
  43     private boolean z = true;
  44     private char c = 'a';
  45     private short s = 3;
  46     private float f = 1.0f;
  47     private double d = 2.0;
  48     private Object l;
  49 
  50     private CallWithJNIWeak() {
  51         this.l = this;
  52     }
  53 
  54     private native void weakReceiverTest0();
  55     private void weakReceiverTest() {
  56         weakReceiverTest0();
  57     }
  58 
  59     private synchronized void synchonizedWeakReceiverTest() {
  60         this.notifyAll();
  61     }
  62 
  63 
  64     private static native void runTests(CallWithJNIWeak o);
  65 
  66     public static void main(String[] args) {
  67         CallWithJNIWeak w = new CallWithJNIWeak();
  68         for (int i = 0; i < 20000; i++) {
  69             runTests(w);
  70         }
  71     }
  72 }