hotspot/test/runtime/BoolReturn/NativeSmallIntCallsTest.java
author coleenp
Tue, 09 Feb 2016 15:54:16 -0500
changeset 37483 8447cff6323d
child 38152 80e5da81fb2c
permissions -rw-r--r--
8149170: Better byte behavior should normalize JNI arguments Summary: Arguments coming from native should be converted to 0=false, 1-255=true Reviewed-by: kvn, kevinw, jrose, bdelsart, gtriantafill
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
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    27
 * @library /testlibrary
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    28
 * @compile BoolConstructor.java
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    29
 * @run main/native NativeSmallIntCallsTest
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    30
 */
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
// 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
    33
// and JNI_FALSE if value returned is 0.
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    34
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    35
import jdk.test.lib.Asserts;
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    36
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    37
public class NativeSmallIntCallsTest {
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    38
    static native boolean nativeCastToBoolCallTrue();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    39
    static native boolean nativeCastToBoolCallFalse();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    40
    static native boolean nativeCallBoolConstructor(int visible, boolean expected);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    41
    static {
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    42
        System.loadLibrary("NativeSmallIntCalls");
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    43
    }
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
    public static void main(java.lang.String[] unused) throws Exception {
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    46
        // Call through jni
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    47
        // JNI makes all results != 0 true for compatibility
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    48
        boolean nativeTrueVal = nativeCastToBoolCallTrue();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    49
        Asserts.assertTrue(nativeTrueVal, "trueval is false!");
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    50
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    51
        boolean nativeFalseVal = nativeCastToBoolCallFalse();
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    52
        Asserts.assertTrue(nativeFalseVal, "falseval is false in native!");
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    53
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    54
        // 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
    55
        nativeCallBoolConstructor(1, true);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    56
        nativeCallBoolConstructor(0x10, true);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    57
        nativeCallBoolConstructor(0x100, false);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    58
        nativeCallBoolConstructor(0x1000, false);
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    59
    }
8447cff6323d 8149170: Better byte behavior should normalize JNI arguments
coleenp
parents:
diff changeset
    60
}