annotate test/compiler/types/correctness/execution/MethodHandleDelegate.java @ 19299:8e4f683e16d9

Truffle-DSL: fixed warning
author Christian Humer <christian.humer@gmail.com>
date Wed, 11 Feb 2015 18:10:02 +0100
parents 534fbe3d90f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17881
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
1 /*
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
4 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
7 * published by the Free Software Foundation.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
8 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
13 * accompanied this code).
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
14 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
18 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
21 * questions.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
22 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
23
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
24 package execution;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
25
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
26 import hierarchies.TypeHierarchy;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
27 import scenarios.Scenario;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
28
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
29 import java.lang.invoke.MethodHandle;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
30 import java.lang.invoke.MethodHandles;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
31 import java.lang.invoke.MethodType;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
32
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
33 /**
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
34 * Executes test scenario using {@link MethodHandle#invoke(Object...)}.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
35 * Delegates execution to the given {@link Execution} by creating
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
36 * new test scenario, see {@link Scenario}
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
37 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
38 public class MethodHandleDelegate<T extends TypeHierarchy.I, R> implements Execution<T, R> {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
39 private final Execution<T, R> delegate;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
40
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
41 public MethodHandleDelegate(Execution<T, R> delegate) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
42 this.delegate = delegate;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
43 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
44
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
45 @Override
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
46 public void execute(Scenario<T, R> scenario) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
47 delegate.execute(new MHScenario<T, R>(scenario));
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
48 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
49
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
50 @Override
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
51 public String getName() {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
52 return "MethodHandleDelegate # " + delegate.getName();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
53 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
54
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
55 private static class MHScenario<T extends TypeHierarchy.I, R> extends Scenario<T, R> {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
56 private final Scenario<T, R> scenario;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
57 private static final MethodHandle METHOD_HANDLE_RUN;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
58
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
59 static {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
60 MethodHandles.Lookup lookup = MethodHandles.lookup();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
61 MethodType methodType = MethodType.methodType(Object.class, TypeHierarchy.I.class);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
62
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
63 try {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
64 METHOD_HANDLE_RUN = lookup.findVirtual(Scenario.class, "run", methodType);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
65 } catch (NoSuchMethodException | IllegalAccessException e) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
66 System.err.println("Failed to get target method run() with " + e);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
67 e.printStackTrace();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
68 throw new RuntimeException(e);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
69 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
70 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
71
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
72 /**
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
73 * Constructor
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
74 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
75 * @param scenario test scenario to be executed
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
76 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
77 private MHScenario(Scenario<T, R> scenario) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
78 super("MethodHandle::" + scenario.getName(), scenario.profilingType, scenario.hierarchy);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
79 this.scenario = scenario;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
80 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
81
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
82 /**
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
83 * Runs {@link Scenario#run(T)} with {@link MethodHandle#invoke(Object...)}
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
84 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
85 * @param t subject of the test
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
86 * @return result of the underlying {@link Scenario#run(T)} invocation
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
87 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
88 @SuppressWarnings("unchecked")
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
89 @Override
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
90 public R run(T t) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
91 try {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
92 return (R) METHOD_HANDLE_RUN.invoke(scenario, t);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
93 } catch (Throwable thr) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
94 System.err.println(scenario.getName()
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
95 + " failed to invoke target method run() with " + thr);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
96 throw new RuntimeException("Invocation failed", thr);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
97 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
98 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
99
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
100 @Override
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
101 public void check(R r, T t) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
102 scenario.check(r, t);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
103 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
104 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
105 }