hotspot/test/runtime/BoolReturn/NativeSmallIntCallsTest.java
author amurillo
Fri, 10 Jun 2016 15:19:32 -0700
changeset 39269 fbef515ea566
parent 38152 80e5da81fb2c
child 40631 ed82623d7831
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37483
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     1
/*
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     4
 *
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     8
 *
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    13
 * accompanied this code).
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    14
 *
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    18
 *
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    21
 * questions.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    22
 */
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    23
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    24
/* @test
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    25
 * @bug 8149170
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    26
 * @summary Test native functions return booleans as 0/1 but differently than java functions
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 37483
diff changeset
    27
 * @modules java.base/jdk.internal.misc
37483
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    28
 * @library /testlibrary
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    29
 * @compile BoolConstructor.java
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    30
 * @run main/native NativeSmallIntCallsTest
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    31
 */
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    32
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    33
// This test shows that returns from native calls for boolean truncate to JNI_TRUE if value != 0
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    34
// and JNI_FALSE if value returned is 0.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    35
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    36
import jdk.test.lib.Asserts;
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    37
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    38
public class NativeSmallIntCallsTest {
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    39
    static native boolean nativeCastToBoolCallTrue();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    40
    static native boolean nativeCastToBoolCallFalse();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    41
    static native boolean nativeCallBoolConstructor(int visible, boolean expected);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    42
    static {
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    43
        System.loadLibrary("NativeSmallIntCalls");
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    44
    }
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    45
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    46
    public static void main(java.lang.String[] unused) throws Exception {
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    47
        // Call through jni
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    48
        // JNI makes all results != 0 true for compatibility
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    49
        boolean nativeTrueVal = nativeCastToBoolCallTrue();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    50
        Asserts.assertTrue(nativeTrueVal, "trueval is false!");
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    51
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    52
        boolean nativeFalseVal = nativeCastToBoolCallFalse();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    53
        Asserts.assertTrue(nativeFalseVal, "falseval is false in native!");
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    54
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    55
        // Call a constructor or method that passes jboolean values into Java from native
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    56
        nativeCallBoolConstructor(1, true);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    57
        nativeCallBoolConstructor(0x10, true);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    58
        nativeCallBoolConstructor(0x100, false);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    59
        nativeCallBoolConstructor(0x1000, false);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    60
    }
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    61
}