1 2 /* 3 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 package runtime.valhalla.valuetypes; 25 26 /* @test 27 * @summary test JNI functions with values 28 * @run main/othervm/native -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueWithJni 29 */ 30 public __ByValue final class ValueWithJni { 31 32 static { 33 System.loadLibrary("ValueWithJni"); 34 } 35 36 public static void main(String[] args) { 37 testJniMonitorOps(); 38 } 39 40 final int x; 41 private ValueWithJni() { x = 0; } 42 43 public native void doJniMonitorEnter(); 44 public native void doJniMonitorExit(); 45 46 public static ValueWithJni createValueWithJni(int x) { 47 ValueWithJni v = __MakeDefault ValueWithJni(); 48 v = __WithField(v.x, x); 49 return v; 50 } 51 52 public static void testJniMonitorOps() { 53 boolean sawImse = false; 54 try { 55 createValueWithJni(0).doJniMonitorEnter(); 56 } catch (Throwable t) { 57 sawImse = checkImse(t); 58 } 59 if (!sawImse) { 60 throw new RuntimeException("JNI MonitorEnter did not fail"); 61 } 62 sawImse = false; 63 try { 64 createValueWithJni(0).doJniMonitorExit(); 65 } catch (Throwable t) { 66 sawImse = checkImse(t); 67 } 68 if (!sawImse) { 69 throw new RuntimeException("JNI MonitorExit did not fail"); 70 } 71 } 72 73 static boolean checkImse(Throwable t) { 74 if (t instanceof IllegalMonitorStateException) { 75 return true; 76 } 77 throw new RuntimeException(t); 78 } 79 }