43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 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 |
package org.graalvm.compiler.hotspot.meta;
|
|
24 |
|
49873
|
25 |
import java.lang.reflect.Type;
|
46459
|
26 |
|
43972
|
27 |
import org.graalvm.compiler.core.common.GraalOptions;
|
|
28 |
import org.graalvm.compiler.graph.Node;
|
|
29 |
import org.graalvm.compiler.graph.iterators.NodeIterable;
|
|
30 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
|
31 |
import org.graalvm.compiler.hotspot.phases.AheadOfTimeVerificationPhase;
|
|
32 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
33 |
import org.graalvm.compiler.nodes.FrameState;
|
|
34 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
|
35 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
|
36 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
|
37 |
import org.graalvm.compiler.nodes.type.StampTool;
|
46459
|
38 |
import org.graalvm.compiler.phases.tiers.CompilerConfiguration;
|
43972
|
39 |
import org.graalvm.compiler.replacements.nodes.MacroNode;
|
|
40 |
|
46459
|
41 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaType;
|
43972
|
42 |
import jdk.vm.ci.meta.JavaKind;
|
|
43 |
import jdk.vm.ci.meta.ResolvedJavaType;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Extension of {@link InvocationPlugins} that disables plugins based on runtime configuration.
|
|
47 |
*/
|
|
48 |
final class HotSpotInvocationPlugins extends InvocationPlugins {
|
46459
|
49 |
private final GraalHotSpotVMConfig config;
|
49873
|
50 |
private final IntrinsificationPredicate intrinsificationPredicate;
|
43972
|
51 |
|
46459
|
52 |
HotSpotInvocationPlugins(GraalHotSpotVMConfig config, CompilerConfiguration compilerConfiguration) {
|
43972
|
53 |
this.config = config;
|
49873
|
54 |
intrinsificationPredicate = new IntrinsificationPredicate(compilerConfiguration);
|
43972
|
55 |
}
|
|
56 |
|
|
57 |
@Override
|
|
58 |
public void register(InvocationPlugin plugin, Type declaringClass, String name, Type... argumentTypes) {
|
|
59 |
if (!config.usePopCountInstruction) {
|
|
60 |
if (name.equals("bitCount")) {
|
|
61 |
assert declaringClass.equals(Integer.class) || declaringClass.equals(Long.class);
|
|
62 |
return;
|
|
63 |
}
|
|
64 |
}
|
|
65 |
super.register(plugin, declaringClass, name, argumentTypes);
|
|
66 |
}
|
|
67 |
|
|
68 |
@Override
|
|
69 |
public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes) {
|
|
70 |
for (Node node : newNodes) {
|
|
71 |
if (node instanceof MacroNode) {
|
|
72 |
// MacroNode based plugins can only be used for inlining since they
|
|
73 |
// require a valid bci should they need to replace themselves with
|
|
74 |
// an InvokeNode during lowering.
|
|
75 |
assert plugin.inlineOnly() : String.format("plugin that creates a %s (%s) must return true for inlineOnly(): %s", MacroNode.class.getSimpleName(), node, plugin);
|
|
76 |
}
|
|
77 |
}
|
46344
|
78 |
if (GraalOptions.ImmutableCode.getValue(b.getOptions())) {
|
43972
|
79 |
for (Node node : newNodes) {
|
|
80 |
if (node.hasUsages() && node instanceof ConstantNode) {
|
|
81 |
ConstantNode c = (ConstantNode) node;
|
|
82 |
if (c.getStackKind() == JavaKind.Object && AheadOfTimeVerificationPhase.isIllegalObjectConstant(c)) {
|
|
83 |
if (isClass(c)) {
|
|
84 |
// This will be handled later by LoadJavaMirrorWithKlassPhase
|
|
85 |
} else {
|
|
86 |
// Tolerate uses in unused FrameStates
|
|
87 |
if (node.usages().filter((n) -> !(n instanceof FrameState) || n.hasUsages()).isNotEmpty()) {
|
|
88 |
throw new AssertionError("illegal constant node in AOT: " + node);
|
|
89 |
}
|
|
90 |
}
|
|
91 |
}
|
|
92 |
}
|
|
93 |
}
|
|
94 |
}
|
|
95 |
super.checkNewNodes(b, plugin, newNodes);
|
|
96 |
}
|
|
97 |
|
|
98 |
private static boolean isClass(ConstantNode node) {
|
|
99 |
ResolvedJavaType type = StampTool.typeOrNull(node);
|
|
100 |
return type != null && "Ljava/lang/Class;".equals(type.getName());
|
|
101 |
}
|
46459
|
102 |
|
|
103 |
@Override
|
48861
|
104 |
public boolean canBeIntrinsified(ResolvedJavaType declaringClass) {
|
46459
|
105 |
if (declaringClass instanceof HotSpotResolvedJavaType) {
|
49873
|
106 |
HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) declaringClass;
|
|
107 |
return intrinsificationPredicate.apply(type.mirror());
|
46459
|
108 |
}
|
|
109 |
return false;
|
|
110 |
}
|
43972
|
111 |
}
|