43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, 2016, 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.replacements;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.replacements.SnippetTemplate.DEFAULT_REPLACER;
|
|
26 |
import static org.graalvm.compiler.replacements.nodes.CStringConstant.cstring;
|
|
27 |
|
|
28 |
import org.graalvm.compiler.api.replacements.Snippet;
|
|
29 |
import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
|
|
30 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
|
46640
|
31 |
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
43972
|
32 |
import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
|
|
33 |
import org.graalvm.compiler.graph.Node.NodeIntrinsic;
|
|
34 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
|
|
35 |
import org.graalvm.compiler.hotspot.nodes.StubStartNode;
|
|
36 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
37 |
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
|
|
38 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
46344
|
39 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
40 |
import org.graalvm.compiler.replacements.SnippetTemplate.AbstractTemplates;
|
|
41 |
import org.graalvm.compiler.replacements.SnippetTemplate.Arguments;
|
|
42 |
import org.graalvm.compiler.replacements.SnippetTemplate.SnippetInfo;
|
|
43 |
import org.graalvm.compiler.replacements.Snippets;
|
|
44 |
import org.graalvm.compiler.replacements.nodes.AssertionNode;
|
|
45 |
import org.graalvm.compiler.word.Word;
|
|
46 |
|
|
47 |
import jdk.vm.ci.code.TargetDescription;
|
|
48 |
|
|
49 |
public class AssertionSnippets implements Snippets {
|
|
50 |
|
|
51 |
/**
|
|
52 |
* This call can only be used with true for the "vmError" parameter, so that it can be
|
|
53 |
* configured to be a leaf method.
|
|
54 |
*/
|
|
55 |
public static final ForeignCallDescriptor ASSERTION_VM_MESSAGE_C = new ForeignCallDescriptor("assertionVmMessageC", void.class, boolean.class, Word.class, long.class, long.class, long.class);
|
|
56 |
|
|
57 |
@Snippet
|
46344
|
58 |
public static void assertion(boolean condition, @ConstantParameter String message) {
|
|
59 |
if (!condition) {
|
43972
|
60 |
vmMessageC(ASSERTION_VM_MESSAGE_C, true, cstring(message), 0L, 0L, 0L);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
@Snippet
|
46344
|
65 |
public static void stubAssertion(boolean condition, @ConstantParameter String message) {
|
|
66 |
if (!condition) {
|
43972
|
67 |
vmMessageC(ASSERTION_VM_MESSAGE_C, true, cstring(message), 0L, 0L, 0L);
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
@NodeIntrinsic(ForeignCallNode.class)
|
|
72 |
static native void vmMessageC(@ConstantNodeParameter ForeignCallDescriptor stubPrintfC, boolean vmError, Word format, long v1, long v2, long v3);
|
|
73 |
|
|
74 |
public static class Templates extends AbstractTemplates {
|
|
75 |
|
|
76 |
private final SnippetInfo assertion = snippet(AssertionSnippets.class, "assertion");
|
|
77 |
private final SnippetInfo stubAssertion = snippet(AssertionSnippets.class, "stubAssertion");
|
|
78 |
|
46640
|
79 |
public Templates(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, TargetDescription target) {
|
|
80 |
super(options, factories, providers, providers.getSnippetReflection(), target);
|
43972
|
81 |
}
|
|
82 |
|
|
83 |
public void lower(AssertionNode assertionNode, LoweringTool tool) {
|
|
84 |
StructuredGraph graph = assertionNode.graph();
|
|
85 |
Arguments args = new Arguments(graph.start() instanceof StubStartNode ? stubAssertion : assertion, graph.getGuardsStage(), tool.getLoweringStage());
|
46344
|
86 |
args.add("condition", assertionNode.condition());
|
43972
|
87 |
args.addConst("message", "failed runtime assertion in snippet/stub: " + assertionNode.message() + " (" + graph.method() + ")");
|
|
88 |
|
46640
|
89 |
template(assertionNode.getDebug(), args).instantiate(providers.getMetaAccess(), assertionNode, DEFAULT_REPLACER, args);
|
43972
|
90 |
}
|
|
91 |
}
|
|
92 |
}
|