hotspot/test/compiler/profiling/TestMethodHandleInvokesIntrinsic.java
author roland
Fri, 25 Apr 2014 09:22:16 +0200
changeset 24313 2e10cd8a870f
child 40059 c2304140ed64
permissions -rw-r--r--
8041481: JVM crashes with collect_args_for_profiling Summary: method handle call to c1 intrinsic tries to profile popped argument Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24313
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     1
/*
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     4
 *
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     8
 *
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    13
 * accompanied this code).
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    14
 *
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    18
 *
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    21
 * questions.
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    22
 */
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    23
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    24
/*
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    25
 * @test
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    26
 * @bug 8041458
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    27
 * @summary profiling of arguments in C1 at MethodHandle invoke of intrinsic tries to profile popped argument.
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    28
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:TieredStopAtLevel=3 TestMethodHandleInvokesIntrinsic
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    29
 *
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    30
 */
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    31
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    32
import java.lang.invoke.*;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    33
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    34
public class TestMethodHandleInvokesIntrinsic {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    35
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    36
    static final MethodHandle mh_nanoTime;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    37
    static final MethodHandle mh_getClass;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    38
    static {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    39
        MethodHandles.Lookup lookup = MethodHandles.lookup();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    40
        MethodType mt = MethodType.methodType(long.class);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    41
        MethodHandle MH = null;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    42
        try {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    43
            MH = lookup.findStatic(System.class, "nanoTime", mt);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    44
        } catch(NoSuchMethodException nsme) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    45
            nsme.printStackTrace();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    46
            throw new RuntimeException("TEST FAILED", nsme);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    47
        } catch(IllegalAccessException iae) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    48
            iae.printStackTrace();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    49
            throw new RuntimeException("TEST FAILED", iae);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    50
        }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    51
        mh_nanoTime = MH;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    52
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    53
        mt = MethodType.methodType(Class.class);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    54
        MH = null;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    55
        try {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    56
            MH = lookup.findVirtual(Object.class, "getClass", mt);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    57
        } catch(NoSuchMethodException nsme) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    58
            nsme.printStackTrace();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    59
            throw new RuntimeException("TEST FAILED", nsme);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    60
        } catch(IllegalAccessException iae) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    61
            iae.printStackTrace();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    62
            throw new RuntimeException("TEST FAILED", iae);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    63
        }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    64
        mh_getClass = MH;
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    65
    }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    66
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    67
    static long m1() throws Throwable {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    68
        return (long)mh_nanoTime.invokeExact();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    69
    }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    70
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    71
    static Class m2(Object o) throws Throwable {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    72
        return (Class)mh_getClass.invokeExact(o);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    73
    }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    74
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    75
    static public void main(String[] args) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    76
        try {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    77
            for (int i = 0; i < 20000; i++) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    78
                m1();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    79
            }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    80
            TestMethodHandleInvokesIntrinsic o = new TestMethodHandleInvokesIntrinsic();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    81
            for (int i = 0; i < 20000; i++) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    82
                m2(o);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    83
            }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    84
        } catch(Throwable t) {
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    85
            System.out.println("Unexpected exception");
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    86
            t.printStackTrace();
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    87
            throw new RuntimeException("TEST FAILED", t);
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    88
        }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    89
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    90
        System.out.println("TEST PASSED");
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    91
    }
2e10cd8a870f 8041481: JVM crashes with collect_args_for_profiling
roland
parents:
diff changeset
    92
}