annotate graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/InstalledCodeExecuteHelperTest.java @ 9025:ff5a32117e02

Implement fast invocation of installed code (direct tail call to the target machine code address).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 12 Apr 2013 01:53:52 +0200
parents 7fee8bd5d2bd
children 640996823a81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
1 /*
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
4 *
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
8 *
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
14 *
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
18 *
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
21 * questions.
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
22 */
8944
e7766460ddb3 Move tests into *.test packages.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8582
diff changeset
23 package com.oracle.graal.hotspot.test;
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
24
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
25 import java.lang.reflect.*;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
26
9025
ff5a32117e02 Implement fast invocation of installed code (direct tail call to the target machine code address).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
27 import com.oracle.graal.api.code.*;
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.api.meta.*;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.api.runtime.*;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
30 import com.oracle.graal.compiler.test.*;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
31 import com.oracle.graal.hotspot.meta.*;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
32 import com.oracle.graal.nodes.spi.*;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
33
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
34 public class InstalledCodeExecuteHelperTest extends GraalCompilerTest {
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
35
8577
6388d983385a Renamings of installed code replacements
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 8564
diff changeset
36 private static final int ITERATIONS = 100000000;
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
37
8959
7fee8bd5d2bd Remove some System.(out|err).print...
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8944
diff changeset
38 // TODO this is not a test, move it somewhere else
7fee8bd5d2bd Remove some System.(out|err).print...
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8944
diff changeset
39 // CheckStyle: stop system..print check
9025
ff5a32117e02 Implement fast invocation of installed code (direct tail call to the target machine code address).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
40 public void test1() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException {
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
41
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
42 final Method benchrMethod = InstalledCodeExecuteHelperTest.class.getMethod("bench", long.class, long.class);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
43 final ResolvedJavaMethod benchJavaMethod = Graal.getRequiredCapability(GraalCodeCacheProvider.class).lookupJavaMethod(benchrMethod);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
44 HotSpotInstalledCode benchCode = (HotSpotInstalledCode) getCode(benchJavaMethod, parse(benchrMethod));
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
45
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
46 final Method wrapperMethod = InstalledCodeExecuteHelperTest.class.getMethod("executeWrapper", long.class, long.class, Object.class, Object.class, Object.class);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
47 final ResolvedJavaMethod wrapperJavaMethod = Graal.getRequiredCapability(GraalCodeCacheProvider.class).lookupJavaMethod(wrapperMethod);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
48 HotSpotInstalledCode wrapperCode = (HotSpotInstalledCode) getCode(wrapperJavaMethod, parse(wrapperMethod));
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
49
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
50 final Method fooMethod = InstalledCodeExecuteHelperTest.class.getMethod("foo", Object.class, Object.class, Object.class);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
51 final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) Graal.getRequiredCapability(GraalCodeCacheProvider.class).lookupJavaMethod(fooMethod);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
52 HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod));
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
53
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
54 System.out.println(wrapperCode.executeVarargs(fooCode.getnmethod(), fooJavaMethod.getMetaspaceMethod(), null, null, null));
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
55
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
56 long nmethod = fooCode.getnmethod();
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
57 long metaspacemethod = fooJavaMethod.getMetaspaceMethod();
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
58
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
59 System.out.println("Without replaced InstalledCode.execute:" + bench(nmethod, metaspacemethod));
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
60
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
61 System.out.println("WITH replaced InstalledCode.execute:" + benchCode.executeVarargs(nmethod, metaspacemethod));
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
62
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
63 }
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
64
8959
7fee8bd5d2bd Remove some System.(out|err).print...
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8944
diff changeset
65 // CheckStyle: resume system..print check
7fee8bd5d2bd Remove some System.(out|err).print...
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8944
diff changeset
66
9025
ff5a32117e02 Implement fast invocation of installed code (direct tail call to the target machine code address).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
67 public static Long bench(long nmethod, long metaspacemethod) throws InvalidInstalledCodeException {
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
68 long start = System.currentTimeMillis();
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
69
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
70 for (int i = 0; i < ITERATIONS; i++) {
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
71 HotSpotInstalledCode.executeHelper(nmethod, metaspacemethod, null, null, null);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
72 }
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
73
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
74 long end = System.currentTimeMillis();
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
75 return (end - start);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
76 }
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
77
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
78 public static Object foo(@SuppressWarnings("unused") Object a1, @SuppressWarnings("unused") Object a2, @SuppressWarnings("unused") Object a3) {
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
79 return 42;
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
80 }
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
81
9025
ff5a32117e02 Implement fast invocation of installed code (direct tail call to the target machine code address).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8959
diff changeset
82 public static Object executeWrapper(long nmethod, long metaspaceMethod, Object arg1, Object arg2, Object arg3) throws InvalidInstalledCodeException {
8564
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
83 return HotSpotInstalledCode.executeHelper(nmethod, metaspaceMethod, arg1, arg2, arg3);
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
84 }
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
85
bbd8167f21f9 Added executeHelper to HotSpotInstalled code that gets replaced by a MethodSubstitution
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
86 }