Skip to content

Commit

Permalink
added support for visiting fields of a Stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Feb 18, 2019
1 parent dc5742f commit d99225b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ protected AbstractObjectStamp(ResolvedJavaType type, boolean exactType, boolean
this.exactType = exactType;
}

@Override
public void accept(Visitor v) {
super.accept(v);
v.visitObject(type);
v.visitBoolean(exactType);
}

protected abstract AbstractObjectStamp copyWith(ResolvedJavaType newType, boolean newExactType, boolean newNonNull, boolean newAlwaysNull);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public abstract class AbstractPointerStamp extends Stamp {
private final boolean nonNull;
private final boolean alwaysNull;

@Override
public void accept(Visitor v) {
v.visitBoolean(nonNull);
v.visitBoolean(alwaysNull);
}

protected AbstractPointerStamp(boolean nonNull, boolean alwaysNull) {
this.nonNull = nonNull;
this.alwaysNull = alwaysNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public final class IllegalStamp extends Stamp {
private IllegalStamp() {
}

@Override
public void accept(Visitor v) {
}

@Override
public JavaKind getStackKind() {
return JavaKind.Illegal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ protected PrimitiveStamp(int bits, ArithmeticOpTable ops) {
this.bits = bits;
}

@Override
public void accept(Visitor v) {
v.visitInt(bits);
}

/**
* The width in bits of the value described by this stamp.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.core.common.spi.LIRKindTool;
import org.graalvm.compiler.serviceprovider.SpeculationReasonGroup.SpeculationContextObject;

import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.JavaKind;
Expand All @@ -36,7 +37,7 @@
/**
* A stamp is the basis for a type system.
*/
public abstract class Stamp {
public abstract class Stamp implements SpeculationContextObject {

protected Stamp() {
}
Expand Down Expand Up @@ -194,12 +195,6 @@ public SymbolicJVMCIReference<? extends Stamp> makeSymbolic() {
return null;
}

/**
* Gets a string value for this stamp that captures all the properties of this stamp and does
* not coincide with the string value of another stamp with different properties. That is, the
* following must hold for two stamps {@code a} and {@code b}:
* {@code a.equals(b) == a.toString().equals(b.toString())}.
*/
@Override
public abstract String toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public final class VoidStamp extends Stamp {
private VoidStamp() {
}

@Override
public void accept(Visitor v) {
}

@Override
public Stamp unrestricted() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ private KlassPointerStamp(boolean nonNull, boolean alwaysNull, CompressEncoding
this.encoding = encoding;
}

@Override
public void accept(Visitor v) {
super.accept(v);
v.visitLong(encoding.getBase());
v.visitInt(encoding.getShift());
}

@Override
protected AbstractPointerStamp copyWith(boolean newNonNull, boolean newAlwaysNull) {
return new KlassPointerStamp(newNonNull, newAlwaysNull, encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static boolean supportOSRWithLocks(OptionValues options) {
return Options.SupportOSRWithLocks.getValue(options);
}

private static final SpeculationReasonGroup OSR_LOCAL_SPECULATIONS = new SpeculationReasonGroup("OSRLocal", int.class, String.class, int.class);
private static final SpeculationReasonGroup OSR_LOCAL_SPECULATIONS = new SpeculationReasonGroup("OSRLocal", int.class, Stamp.class, int.class);

@Override
@SuppressWarnings("try")
Expand Down Expand Up @@ -207,7 +207,7 @@ protected void run(StructuredGraph graph) {
osrLocal = graph.addOrUnique(new OSRLocalNode(i, unrestrictedStamp));
}
// Speculate on the OSRLocal stamps that could be more precise.
SpeculationReason reason = OSR_LOCAL_SPECULATIONS.createSpeculationReason(osrState.bci, narrowedStamp.toString(), i);
SpeculationReason reason = OSR_LOCAL_SPECULATIONS.createSpeculationReason(osrState.bci, narrowedStamp, i);
if (graph.getSpeculationLog().maySpeculate(reason) && osrLocal instanceof OSRLocalNode && value.getStackKind().equals(JavaKind.Object) && !narrowedStamp.isUnrestricted()) {
// Add guard.
LogicNode check = graph.addOrUniqueWithInputs(InstanceOfNode.createHelper((ObjectStamp) narrowedStamp, osrLocal, null, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ protected NarrowOopStamp(ResolvedJavaType type, boolean exactType, boolean nonNu
this.encoding = encoding;
}

@Override
public void accept(Visitor v) {
super.accept(v);
v.visitLong(encoding.getBase());
v.visitInt(encoding.getShift());
}

@Override
protected abstract AbstractObjectStamp copyWith(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String toString() {
/**
* Creates a speculation reason described by this group.
*
* @param context the details of the reason instance being created
* @param context the components of the reason instance being created
*/
public SpeculationReason createSpeculationReason(Object... context) {
assert checkSignature(context);
Expand All @@ -90,6 +90,9 @@ private static boolean isOfSupportedType(Class<?> c) {
// Trust the ordinal of an Enum to be unique
return true;
}
if (SpeculationContextObject.class.isAssignableFrom(c)) {
return true;
}
if (ResolvedJavaMethod.class.isAssignableFrom(c) || ResolvedJavaType.class.isAssignableFrom(c)) {
// Only the JVMCI implementation specific concrete subclasses
// of these types will be accepted but we cannot test for that
Expand Down Expand Up @@ -121,7 +124,7 @@ private boolean checkSignature(Object[] context) {
Object o = context[i];
Class<?> c = signature[i];
if (o != null) {
if (c == ResolvedJavaMethod.class || c == ResolvedJavaType.class) {
if (c == ResolvedJavaMethod.class || c == ResolvedJavaType.class || SpeculationContextObject.class.isAssignableFrom(c)) {
c.cast(o);
} else {
Class<?> oClass = o.getClass();
Expand All @@ -135,4 +138,32 @@ private boolean checkSignature(Object[] context) {
}
return true;
}

/**
* Denotes part of a {@linkplain SpeculationReasonGroup#createSpeculationReason(Object...)
* reason} that can have its attributes {@linkplain #accept(Visitor) visited}.
*/
public interface SpeculationContextObject {
void accept(Visitor v);

public interface Visitor {
void visitBoolean(boolean v);

void visitByte(byte v);

void visitChar(char v);

void visitShort(short v);

void visitInt(int v);

void visitLong(long v);

void visitFloat(float v);

void visitDouble(double v);

void visitObject(Object v);
}
}
}

0 comments on commit d99225b

Please sign in to comment.