Path: blob/master/test/hotspot/jtreg/compiler/profiling/TestMethodHandleInvokesIntrinsic.java
41152 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 804145826* @summary profiling of arguments in C1 at MethodHandle invoke of intrinsic tries to profile popped argument.27*28* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement29* -XX:TieredStopAtLevel=330* compiler.profiling.TestMethodHandleInvokesIntrinsic31*32*/3334package compiler.profiling;3536import java.lang.invoke.MethodHandle;37import java.lang.invoke.MethodHandles;38import java.lang.invoke.MethodType;3940public class TestMethodHandleInvokesIntrinsic {4142static final MethodHandle mh_nanoTime;43static final MethodHandle mh_getClass;44static {45MethodHandles.Lookup lookup = MethodHandles.lookup();46MethodType mt = MethodType.methodType(long.class);47MethodHandle MH = null;48try {49MH = lookup.findStatic(System.class, "nanoTime", mt);50} catch(NoSuchMethodException nsme) {51nsme.printStackTrace();52throw new RuntimeException("TEST FAILED", nsme);53} catch(IllegalAccessException iae) {54iae.printStackTrace();55throw new RuntimeException("TEST FAILED", iae);56}57mh_nanoTime = MH;5859mt = MethodType.methodType(Class.class);60MH = null;61try {62MH = lookup.findVirtual(Object.class, "getClass", mt);63} catch(NoSuchMethodException nsme) {64nsme.printStackTrace();65throw new RuntimeException("TEST FAILED", nsme);66} catch(IllegalAccessException iae) {67iae.printStackTrace();68throw new RuntimeException("TEST FAILED", iae);69}70mh_getClass = MH;71}7273static long m1() throws Throwable {74return (long)mh_nanoTime.invokeExact();75}7677static Class m2(Object o) throws Throwable {78return (Class)mh_getClass.invokeExact(o);79}8081static public void main(String[] args) {82try {83for (int i = 0; i < 20000; i++) {84m1();85}86TestMethodHandleInvokesIntrinsic o = new TestMethodHandleInvokesIntrinsic();87for (int i = 0; i < 20000; i++) {88m2(o);89}90} catch(Throwable t) {91System.out.println("Unexpected exception");92t.printStackTrace();93throw new RuntimeException("TEST FAILED", t);94}9596System.out.println("TEST PASSED");97}98}99100101