hotspot/test/runtime/Unsafe/GetPutFloat.java
author ctornqvi
Fri, 23 Jan 2015 11:44:21 -0800
changeset 28732 d4b650e48a8f
child 28951 a29d2048e16a
permissions -rw-r--r--
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit Reviewed-by: gtriantafill, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28732
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     1
/*
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     4
 *
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     8
 *
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    14
 *
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    18
 *
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    21
 * questions.
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    22
 */
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    23
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    24
/*
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    25
 * @test
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    26
 * @summary Verify behaviour of Unsafe.get/putFloat
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    27
 * @library /testlibrary
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    28
 * @run main GetPutFloat
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    29
 */
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    30
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    31
import java.lang.reflect.Field;
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    32
import com.oracle.java.testlibrary.*;
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    33
import sun.misc.Unsafe;
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    34
import static com.oracle.java.testlibrary.Asserts.*;
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    35
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    36
public class GetPutFloat {
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    37
    public static void main(String args[]) throws Exception {
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    38
        Unsafe unsafe = Utils.getUnsafe();
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    39
        Test t = new Test();
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    40
        Field field = Test.class.getField("f");
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    41
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    42
        int offset = unsafe.fieldOffset(field);
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    43
        assertEquals(-1.0f, unsafe.getFloat(t, offset));
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    44
        unsafe.putFloat(t, offset, 0.0f);
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    45
        assertEquals(0.0f, unsafe.getFloat(t, offset));
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    46
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    47
        long address = unsafe.allocateMemory(8);
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    48
        unsafe.putFloat(address, 1.0f);
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    49
        assertEquals(1.0f, unsafe.getFloat(address));
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    50
        unsafe.freeMemory(address);
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    51
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    52
        float arrayFloat[] = { -1.0f, 0.0f, 1.0f, 2.0f };
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    53
        int scale = unsafe.arrayIndexScale(arrayFloat.getClass());
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    54
        offset = unsafe.arrayBaseOffset(arrayFloat.getClass());
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    55
        for (int i = 0; i < arrayFloat.length; i++) {
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    56
            assertEquals(unsafe.getFloat(arrayFloat, offset), arrayFloat[i]);
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    57
            offset += scale;
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    58
        }
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    59
    }
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    60
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    61
    static class Test {
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    62
        public float f = -1.0f;
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    63
    }
d4b650e48a8f 8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff changeset
    64
}