Skip to content

Commit 252d91b

Browse files
pecimuthdougxc
authored andcommitted
8357689: Refactor JVMCI to enable replay compilation in Graal
Reviewed-by: dnsimon (cherry picked from commit 963b83f)
1 parent 655345c commit 252d91b

16 files changed

+251
-34
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/BytecodeFrame.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,11 @@ public boolean equals(Object obj) {
387387
public String toString() {
388388
return CodeUtil.append(new StringBuilder(100), this).toString();
389389
}
390+
391+
/**
392+
* Returns a copy of the array describing the Java kinds in {@link #values}.
393+
*/
394+
public JavaKind[] getSlotKinds() {
395+
return (slotKinds == null) ? null : slotKinds.clone();
396+
}
390397
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/VirtualObject.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,18 @@ public boolean equals(Object o) {
289289
if (o == this) {
290290
return true;
291291
}
292-
if (o instanceof VirtualObject) {
293-
VirtualObject l = (VirtualObject) o;
294-
if (!l.type.equals(type) || l.values.length != values.length) {
292+
if (o instanceof VirtualObject that) {
293+
int thatValuesLength = (that.values == null) ? 0 : that.values.length;
294+
int valuesLength = (values == null) ? 0 : values.length;
295+
if (!that.type.equals(type) || thatValuesLength != valuesLength) {
295296
return false;
296297
}
297-
for (int i = 0; i < values.length; i++) {
298+
for (int i = 0; i < valuesLength; i++) {
298299
/*
299300
* Virtual objects can form cycles. Calling equals() could therefore lead to
300301
* infinite recursion.
301302
*/
302-
if (!same(values[i], l.values[i])) {
303+
if (!same(values[i], that.values[i])) {
303304
return false;
304305
}
305306
}
@@ -311,4 +312,11 @@ public boolean equals(Object o) {
311312
private static boolean same(Object o1, Object o2) {
312313
return o1 == o2;
313314
}
315+
316+
/**
317+
* Returns a copy of the array containing the Java kinds of the values stored in this virtual object.
318+
*/
319+
public JavaKind[] getSlotKinds() {
320+
return (slotKinds == null) ? null : slotKinds.clone();
321+
}
314322
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/site/Site.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public Site(int pos) {
3939
}
4040

4141
@Override
42-
public final int hashCode() {
43-
throw new UnsupportedOperationException("hashCode");
42+
public int hashCode() {
43+
return 41 * pcOffset;
4444
}
4545

4646
@Override

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledCode.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,88 @@ public int getOffset(ResolvedJavaField field) {
188188
}
189189
});
190190
}
191+
192+
/**
193+
* Returns a copy of the compiled machine code.
194+
*/
195+
public byte[] getTargetCode() {
196+
return (targetCode == null) ? null : targetCode.clone();
197+
}
198+
199+
/**
200+
* Gets the size of the compiled machine code in bytes.
201+
*/
202+
public int getTargetCodeSize() {
203+
return targetCodeSize;
204+
}
205+
206+
/**
207+
* Returns a copy of the code annotations describing special sites in {@link #targetCode}.
208+
*/
209+
public Site[] getSites() {
210+
return (sites == null) ? null : sites.clone();
211+
}
212+
213+
/**
214+
* Returns an array copy of the assumptions this code relies on.
215+
*/
216+
public Assumption[] getAssumptions() {
217+
return (assumptions == null) ? null : assumptions.clone();
218+
}
219+
220+
/**
221+
* Returns an array copy of the methods whose bytecodes were used as input to the compilation.
222+
*/
223+
public ResolvedJavaMethod[] getMethods() {
224+
return (methods == null) ? null : methods.clone();
225+
}
226+
227+
/**
228+
* Returns an array copy of the comments that are included in code dumps.
229+
*/
230+
public Comment[] getComments() {
231+
return (comments == null) ? null : comments.clone();
232+
}
233+
234+
/**
235+
* Returns a copy of the data section containing serialized constants for the emitted machine code.
236+
*/
237+
public byte[] getDataSection() {
238+
return (dataSection == null) ? null : dataSection.clone();
239+
}
240+
241+
/**
242+
* Gets the minimum alignment of the data section.
243+
*/
244+
public int getDataSectionAlignment() {
245+
return dataSectionAlignment;
246+
}
247+
248+
/**
249+
* Returns a copy of the {@link #dataSection} relocations.
250+
*/
251+
public DataPatch[] getDataSectionPatches() {
252+
return (dataSectionPatches == null) ? null : dataSectionPatches.clone();
253+
}
254+
255+
/**
256+
* Checks if this compiled code is immutable and position independent.
257+
*/
258+
public boolean isImmutablePIC() {
259+
return isImmutablePIC;
260+
}
261+
262+
/**
263+
* Gets the total size of the stack frame of this compiled method.
264+
*/
265+
public int getTotalFrameSize() {
266+
return totalFrameSize;
267+
}
268+
269+
/**
270+
* Gets the deoptimization rescue slot associated with this compiled code.
271+
*/
272+
public StackSlot getDeoptRescueSlot() {
273+
return deoptRescueSlot;
274+
}
191275
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotCompiledNmethod.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,44 @@ public boolean hasScopedAccess() {
118118
return false;
119119
}
120120

121+
/**
122+
* Returns the method to which this compiled nmethod belongs.
123+
*/
124+
public HotSpotResolvedJavaMethod getMethod() {
125+
return method;
126+
}
127+
128+
/**
129+
* Returns the bytecode index (BCI) in the {@link #getMethod() method} that is the beginning of this compiled
130+
* nmethod. -1 denotes the beginning of the method.
131+
*
132+
* @return the entry BCI of this nmethod or -1 if the entry is the method's beginning
133+
*/
134+
public int getEntryBCI() {
135+
return entryBCI;
136+
}
137+
138+
/**
139+
* Returns the identifier of the compilation request.
140+
*/
141+
public int getId() {
142+
return id;
143+
}
144+
145+
/**
146+
* Returns the address of a native {@code JVMCICompileState} object associated with this compiled nmethod.
147+
* If no such object exists, it returns 0L.
148+
*
149+
* @return the address of the native {@code JVMCICompileState} object or 0L if it does not exist
150+
*/
151+
public long getCompileState() {
152+
return compileState;
153+
}
154+
155+
/**
156+
* Checks if this compiled nmethod has a memory access via the {@code Unsafe} class.
157+
*/
158+
public boolean hasUnsafeAccess() {
159+
return hasUnsafeAccess;
160+
}
121161
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJavaType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public HotSpotJavaType(String name) {
3636
}
3737

3838
@Override
39-
public final String getName() {
39+
public String getName() {
4040
return name;
4141
}
4242
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstant.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
*/
2323
package jdk.vm.ci.hotspot;
2424

25-
import java.lang.invoke.CallSite;
26-
import java.util.Objects;
27-
2825
import jdk.vm.ci.meta.Assumptions;
2926
import jdk.vm.ci.meta.JavaConstant;
3027
import jdk.vm.ci.meta.ResolvedJavaType;
3128
import jdk.vm.ci.meta.VMConstant;
3229

30+
import java.lang.invoke.CallSite;
31+
import java.lang.invoke.ConstantCallSite;
32+
import java.util.Objects;
33+
3334
/**
3435
* Represents a constant non-{@code null} object reference, within the compiler and across the
3536
* compiler/runtime interface.
@@ -61,7 +62,26 @@ public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VM
6162
* change
6263
* @return {@code null} if this constant does not represent a {@link CallSite} object
6364
*/
64-
JavaConstant getCallSiteTarget(Assumptions assumptions);
65+
default JavaConstant getCallSiteTarget(Assumptions assumptions) {
66+
Assumptions.AssumptionResult<JavaConstant> result = getCallSiteTarget();
67+
if (!result.canRecordTo(assumptions)) {
68+
return null;
69+
}
70+
result.recordTo(assumptions);
71+
return result.getResult();
72+
}
73+
74+
/**
75+
* Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented
76+
* by this constant. The target is bound to an assumption if this is not a fully initialized
77+
* {@link ConstantCallSite}.
78+
*
79+
* @return a call-site target (possibly bound to an assumption) or {@code null} if this constant
80+
* does not represent a {@link CallSite} object
81+
*/
82+
default Assumptions.AssumptionResult<JavaConstant> getCallSiteTarget() {
83+
throw new UnsupportedOperationException("getCallSiteTarget");
84+
}
6585

6686
/**
6787
* Determines if this constant represents an {@linkplain String#intern() interned} string.

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,15 @@ private HotSpotObjectConstantImpl readTarget() {
8989
}
9090

9191
@Override
92-
public JavaConstant getCallSiteTarget(Assumptions assumptions) {
92+
public Assumptions.AssumptionResult<JavaConstant> getCallSiteTarget() {
9393
if (runtime().getCallSite().isInstance(this)) {
9494
// For ConstantCallSites, we need to read "isFrozen" before reading "target"
9595
// isFullyInitializedConstantCallSite() reads "isFrozen"
9696
if (isFullyInitializedConstantCallSite()) {
97-
return readTarget();
98-
}
99-
if (assumptions == null) {
100-
return null;
97+
return new Assumptions.AssumptionResult<>(readTarget());
10198
}
10299
HotSpotObjectConstantImpl result = readTarget();
103-
assumptions.record(new Assumptions.CallSiteTargetValue(this, result));
104-
return result;
100+
return new Assumptions.AssumptionResult<>(result, new Assumptions.CallSiteTargetValue(this, result));
105101
}
106102
return null;
107103
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaType.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,32 @@
3030

3131
public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements ResolvedJavaType {
3232

33-
HotSpotResolvedObjectTypeImpl arrayOfType;
33+
HotSpotResolvedObjectType arrayOfType;
3434

35-
HotSpotResolvedJavaType(String name) {
35+
protected HotSpotResolvedJavaType(String name) {
3636
super(name);
3737
}
3838

3939
@Override
4040
public abstract boolean equals(Object obj);
4141

4242
@Override
43-
public final int hashCode() {
43+
public int hashCode() {
4444
return getName().hashCode();
4545
}
4646

47-
abstract JavaConstant getJavaMirror();
47+
/**
48+
* Gets the runtime representation of the {@link Class} object of this type.
49+
*/
50+
public abstract JavaConstant getJavaMirror();
4851

49-
abstract HotSpotResolvedObjectTypeImpl getArrayType();
52+
/**
53+
* Gets the array type of this type without caching the result.
54+
*/
55+
protected abstract HotSpotResolvedObjectType getArrayType();
5056

5157
@Override
52-
public final HotSpotResolvedObjectType getArrayClass() {
58+
public HotSpotResolvedObjectType getArrayClass() {
5359
if (arrayOfType == null) {
5460
arrayOfType = getArrayType();
5561
}
@@ -63,7 +69,7 @@ public final HotSpotResolvedObjectType getArrayClass() {
6369
*
6470
* @return {@code true} if this type is being initialized
6571
*/
66-
abstract boolean isBeingInitialized();
72+
protected abstract boolean isBeingInitialized();
6773

6874
static void checkIsAnnotation(ResolvedJavaType type) {
6975
if (!type.isAnnotation()) {

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectType.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ default JavaKind getJavaKind() {
8080
@Override
8181
AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method);
8282

83+
/**
84+
* Gets the runtime representation of the {@link Class} object of this type.
85+
*/
86+
default JavaConstant getJavaMirror() {
87+
throw new UnsupportedOperationException("getJavaMirror");
88+
}
89+
8390
/**
8491
* Performs a fast-path check that this type is resolved in the context of a given accessing
8592
* class. A negative result does not mean this type is not resolved with respect to

0 commit comments

Comments
 (0)