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