43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 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.nodes.spi;
|
|
24 |
|
|
25 |
import java.util.List;
|
|
26 |
|
48861
|
27 |
import org.graalvm.compiler.core.common.spi.ArrayOffsetProvider;
|
46640
|
28 |
import org.graalvm.compiler.debug.DebugContext;
|
47798
|
29 |
import org.graalvm.compiler.debug.GraalError;
|
43972
|
30 |
import org.graalvm.compiler.graph.Node;
|
|
31 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
32 |
import org.graalvm.compiler.nodes.java.MonitorIdNode;
|
|
33 |
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
46344
|
34 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
35 |
|
|
36 |
import jdk.vm.ci.meta.ConstantReflectionProvider;
|
|
37 |
import jdk.vm.ci.meta.JavaConstant;
|
|
38 |
import jdk.vm.ci.meta.JavaKind;
|
|
39 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* This tool can be used to query the current state (normal/virtualized/re-materialized) of values
|
|
43 |
* and to describe the actions that would be taken for this state.
|
|
44 |
*
|
|
45 |
* See also {@link Virtualizable}.
|
|
46 |
*/
|
|
47 |
public interface VirtualizerTool {
|
|
48 |
|
|
49 |
/**
|
|
50 |
* @return the {@link MetaAccessProvider} associated with the current compilation.
|
|
51 |
*/
|
|
52 |
MetaAccessProvider getMetaAccessProvider();
|
|
53 |
|
|
54 |
/**
|
|
55 |
* @return the {@link ConstantReflectionProvider} associated with the current compilation, which
|
|
56 |
* can be used to access {@link JavaConstant}s.
|
|
57 |
*/
|
|
58 |
ConstantReflectionProvider getConstantReflectionProvider();
|
|
59 |
|
48861
|
60 |
ArrayOffsetProvider getArrayOffsetProvider();
|
|
61 |
|
43972
|
62 |
/**
|
|
63 |
* This method should be used to query the maximum size of virtualized objects before attempting
|
|
64 |
* virtualization.
|
|
65 |
*
|
|
66 |
* @return the maximum number of entries for virtualized objects.
|
|
67 |
*/
|
|
68 |
int getMaximumEntryCount();
|
|
69 |
|
|
70 |
// methods working on virtualized/materialized objects
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Introduces a new virtual object to the current state.
|
|
74 |
*
|
|
75 |
* @param virtualObject the new virtual object.
|
|
76 |
* @param entryState the initial state of the virtual object's fields.
|
|
77 |
* @param locks the initial locking depths.
|
|
78 |
* @param ensureVirtualized true if this object needs to stay virtual
|
|
79 |
*/
|
|
80 |
void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, List<MonitorIdNode> locks, boolean ensureVirtualized);
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Returns a VirtualObjectNode if the given value is aliased with a virtual object that is still
|
|
84 |
* virtual, the materialized value of the given value is aliased with a virtual object that was
|
|
85 |
* materialized, the replacement if the give value was replaced, otherwise the given value.
|
|
86 |
*
|
|
87 |
* Replacements via {@link #replaceWithValue(ValueNode)} are not immediately committed. This
|
|
88 |
* method can be used to determine if a value was replaced by another one (e.g., a load field by
|
|
89 |
* the loaded value).
|
|
90 |
*/
|
|
91 |
ValueNode getAlias(ValueNode value);
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Sets the entry (field or array element) with the given index in the virtualized object.
|
|
95 |
*
|
|
96 |
* @param index the index to be set.
|
|
97 |
* @param value the new value for the given index.
|
47798
|
98 |
* @param accessKind the kind of the store which might be different than
|
|
99 |
* {@link VirtualObjectNode#entryKind(int)}.
|
|
100 |
* @return true if the operation was permitted
|
43972
|
101 |
*/
|
47798
|
102 |
boolean setVirtualEntry(VirtualObjectNode virtualObject, int index, ValueNode value, JavaKind accessKind, long offset);
|
|
103 |
|
|
104 |
default void setVirtualEntry(VirtualObjectNode virtualObject, int index, ValueNode value) {
|
|
105 |
if (!setVirtualEntry(virtualObject, index, value, null, 0)) {
|
|
106 |
throw new GraalError("unexpected failure when updating virtual entry");
|
|
107 |
}
|
|
108 |
}
|
43972
|
109 |
|
|
110 |
ValueNode getEntry(VirtualObjectNode virtualObject, int index);
|
|
111 |
|
|
112 |
void addLock(VirtualObjectNode virtualObject, MonitorIdNode monitorId);
|
|
113 |
|
|
114 |
MonitorIdNode removeLock(VirtualObjectNode virtualObject);
|
|
115 |
|
|
116 |
void setEnsureVirtualized(VirtualObjectNode virtualObject, boolean ensureVirtualized);
|
|
117 |
|
|
118 |
boolean getEnsureVirtualized(VirtualObjectNode virtualObject);
|
|
119 |
|
|
120 |
// operations on the current node
|
|
121 |
|
|
122 |
/**
|
|
123 |
* Deletes the current node and replaces it with the given virtualized object.
|
|
124 |
*
|
|
125 |
* @param virtualObject the virtualized object that should replace the current node.
|
|
126 |
*/
|
|
127 |
void replaceWithVirtual(VirtualObjectNode virtualObject);
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Deletes the current node and replaces it with the given value.
|
|
131 |
*
|
|
132 |
* @param replacement the value that should replace the current node.
|
|
133 |
*/
|
|
134 |
void replaceWithValue(ValueNode replacement);
|
|
135 |
|
|
136 |
/**
|
|
137 |
* Deletes the current node.
|
|
138 |
*/
|
|
139 |
void delete();
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Replaces an input of the current node.
|
|
143 |
*
|
|
144 |
* @param oldInput the old input value.
|
|
145 |
* @param replacement the new input value.
|
|
146 |
*/
|
|
147 |
void replaceFirstInput(Node oldInput, Node replacement);
|
|
148 |
|
|
149 |
/**
|
|
150 |
* Adds the given node to the graph.This action will only be performed when, and if, the changes
|
|
151 |
* are committed.
|
|
152 |
*
|
|
153 |
* @param node the node to add.
|
|
154 |
*/
|
|
155 |
void addNode(ValueNode node);
|
|
156 |
|
|
157 |
/**
|
|
158 |
* This method performs either {@link #replaceWithValue(ValueNode)} or
|
|
159 |
* {@link #replaceWithVirtual(VirtualObjectNode)}, depending on the given value.
|
|
160 |
*
|
|
161 |
* @param value the replacement value
|
|
162 |
*/
|
|
163 |
void replaceWith(ValueNode value);
|
|
164 |
|
|
165 |
/**
|
|
166 |
*
|
|
167 |
* If state is virtual, materialization is performed for the given state.
|
|
168 |
*
|
|
169 |
* @return true if materialization happened, false if not.
|
|
170 |
*/
|
|
171 |
boolean ensureMaterialized(VirtualObjectNode virtualObject);
|
46344
|
172 |
|
|
173 |
OptionValues getOptions();
|
46640
|
174 |
|
|
175 |
DebugContext getDebug();
|
43972
|
176 |
}
|