Skip to content

Commit

Permalink
moved factory methods into jdk.graal.compiler.word.Word
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Dec 20, 2024
1 parent 59ff18f commit 9f429e9
Show file tree
Hide file tree
Showing 316 changed files with 2,199 additions and 1,832 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
import jdk.graal.compiler.nodes.spi.CoreProviders;
import jdk.graal.compiler.phases.VerifyPhase;
import jdk.vm.ci.meta.MetaUtil;
import jdk.graal.compiler.word.Word;
import jdk.vm.ci.meta.ResolvedJavaType;
import org.graalvm.word.WordFactory;

/**
* Ensures that Graal compiler code uses {@link jdk.graal.compiler.word.WordFactory} instead of
* {@link org.graalvm.word.WordFactory} to create word values.
* Ensures that Graal compiler code uses factory methods in {@link Word} instead of
* {@link WordFactory} to create word values.
*/
public class VerifyWordFactoryUsage extends VerifyPhase<CoreProviders> {

Expand All @@ -44,14 +46,14 @@ public boolean checkContract() {
@Override
protected void verify(StructuredGraph graph, CoreProviders context) {

String badWordFactory = MetaUtil.toInternalName(org.graalvm.word.WordFactory.class.getName());

ResolvedJavaType wordFactory = context.getMetaAccess().lookupJavaType(WordFactory.class);
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
if (t.targetMethod().getDeclaringClass().getName().equals(badWordFactory)) {
throw new VerificationError("accessing %s in %s is prohibited - use %s instead",
badWordFactory,
if (t.targetMethod().getDeclaringClass().equals(wordFactory)) {
throw new VerificationError("accessing %s in %s is prohibited - use %s.%s instead",
wordFactory.toJavaName(),
graph.method().format("%H.%n(%p)"),
jdk.graal.compiler.word.WordFactory.class.getName());
Word.class.getName(),
graph.method().format("%n(%p)"));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import jdk.graal.compiler.nodes.extended.JavaWriteNode;
import jdk.graal.compiler.nodes.memory.address.OffsetAddressNode;
import jdk.graal.compiler.word.ObjectAccess;
import jdk.graal.compiler.word.Word;
import org.graalvm.word.LocationIdentity;
import org.graalvm.word.Pointer;
import jdk.graal.compiler.word.WordFactory;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -152,7 +152,7 @@ public static byte readByte1(Object o, int offset) {

@Snippet
public static byte readByte2(Object o, int offset) {
return ObjectAccess.readByte(o, WordFactory.signed(offset), ID);
return ObjectAccess.readByte(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -167,7 +167,7 @@ public static void writeByte1(Object o, int offset, byte value) {

@Snippet
public static void writeByte2(Object o, int offset, byte value) {
ObjectAccess.writeByte(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeByte(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -182,7 +182,7 @@ public static char readChar1(Object o, int offset) {

@Snippet
public static char readChar2(Object o, int offset) {
return ObjectAccess.readChar(o, WordFactory.signed(offset), ID);
return ObjectAccess.readChar(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -197,7 +197,7 @@ public static void writeChar1(Object o, int offset, char value) {

@Snippet
public static void writeChar2(Object o, int offset, char value) {
ObjectAccess.writeChar(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeChar(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -212,7 +212,7 @@ public static short readShort1(Object o, int offset) {

@Snippet
public static short readShort2(Object o, int offset) {
return ObjectAccess.readShort(o, WordFactory.signed(offset), ID);
return ObjectAccess.readShort(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -227,7 +227,7 @@ public static void writeShort1(Object o, int offset, short value) {

@Snippet
public static void writeShort2(Object o, int offset, short value) {
ObjectAccess.writeShort(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeShort(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -242,7 +242,7 @@ public static int readInt1(Object o, int offset) {

@Snippet
public static int readInt2(Object o, int offset) {
return ObjectAccess.readInt(o, WordFactory.signed(offset), ID);
return ObjectAccess.readInt(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -257,7 +257,7 @@ public static void writeInt1(Object o, int offset, int value) {

@Snippet
public static void writeInt2(Object o, int offset, int value) {
ObjectAccess.writeInt(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeInt(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -272,7 +272,7 @@ public static long readLong1(Object o, int offset) {

@Snippet
public static long readLong2(Object o, int offset) {
return ObjectAccess.readLong(o, WordFactory.signed(offset), ID);
return ObjectAccess.readLong(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -287,7 +287,7 @@ public static void writeLong1(Object o, int offset, long value) {

@Snippet
public static void writeLong2(Object o, int offset, long value) {
ObjectAccess.writeLong(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeLong(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -302,7 +302,7 @@ public static float readFloat1(Object o, int offset) {

@Snippet
public static float readFloat2(Object o, int offset) {
return ObjectAccess.readFloat(o, WordFactory.signed(offset), ID);
return ObjectAccess.readFloat(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -317,7 +317,7 @@ public static void writeFloat1(Object o, int offset, float value) {

@Snippet
public static void writeFloat2(Object o, int offset, float value) {
ObjectAccess.writeFloat(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeFloat(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -332,7 +332,7 @@ public static double readDouble1(Object o, int offset) {

@Snippet
public static double readDouble2(Object o, int offset) {
return ObjectAccess.readDouble(o, WordFactory.signed(offset), ID);
return ObjectAccess.readDouble(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -347,7 +347,7 @@ public static void writeDouble1(Object o, int offset, double value) {

@Snippet
public static void writeDouble2(Object o, int offset, double value) {
ObjectAccess.writeDouble(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeDouble(o, Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -362,7 +362,7 @@ public static Object readObject1(Object o, int offset) {

@Snippet
public static Object readObject2(Object o, int offset) {
return ObjectAccess.readObject(o, WordFactory.signed(offset), ID);
return ObjectAccess.readObject(o, Word.signed(offset), ID);
}

@Snippet
Expand All @@ -377,7 +377,7 @@ public static void writeObject1(Object o, int offset, Object value) {

@Snippet
public static void writeObject2(Object o, int offset, Object value) {
ObjectAccess.writeObject(o, WordFactory.signed(offset), value, ID);
ObjectAccess.writeObject(o, Word.signed(offset), value, ID);
}

@Snippet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import jdk.graal.compiler.word.WordCastNode;
import org.graalvm.word.LocationIdentity;
import org.graalvm.word.Pointer;
import jdk.graal.compiler.word.WordFactory;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -172,7 +171,7 @@ public static byte readByte1(Object o, int offset) {

@Snippet
public static byte readByte2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readByte(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readByte(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -187,7 +186,7 @@ public static void writeByte1(Object o, int offset, byte value) {

@Snippet
public static void writeByte2(Object o, int offset, byte value) {
Word.objectToTrackedPointer(o).writeByte(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeByte(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -202,7 +201,7 @@ public static char readChar1(Object o, int offset) {

@Snippet
public static char readChar2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readChar(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readChar(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -217,7 +216,7 @@ public static void writeChar1(Object o, int offset, char value) {

@Snippet
public static void writeChar2(Object o, int offset, char value) {
Word.objectToTrackedPointer(o).writeChar(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeChar(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -232,7 +231,7 @@ public static short readShort1(Object o, int offset) {

@Snippet
public static short readShort2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readShort(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readShort(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -247,7 +246,7 @@ public static void writeShort1(Object o, int offset, short value) {

@Snippet
public static void writeShort2(Object o, int offset, short value) {
Word.objectToTrackedPointer(o).writeShort(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeShort(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -262,7 +261,7 @@ public static int readInt1(Object o, int offset) {

@Snippet
public static int readInt2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readInt(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readInt(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -277,7 +276,7 @@ public static void writeInt1(Object o, int offset, int value) {

@Snippet
public static void writeInt2(Object o, int offset, int value) {
Word.objectToTrackedPointer(o).writeInt(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeInt(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -292,7 +291,7 @@ public static long readLong1(Object o, int offset) {

@Snippet
public static long readLong2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readLong(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readLong(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -307,7 +306,7 @@ public static void writeLong1(Object o, int offset, long value) {

@Snippet
public static void writeLong2(Object o, int offset, long value) {
Word.objectToTrackedPointer(o).writeLong(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeLong(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -322,7 +321,7 @@ public static float readFloat1(Object o, int offset) {

@Snippet
public static float readFloat2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readFloat(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readFloat(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -337,7 +336,7 @@ public static void writeFloat1(Object o, int offset, float value) {

@Snippet
public static void writeFloat2(Object o, int offset, float value) {
Word.objectToTrackedPointer(o).writeFloat(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeFloat(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -352,7 +351,7 @@ public static double readDouble1(Object o, int offset) {

@Snippet
public static double readDouble2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readDouble(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readDouble(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -367,7 +366,7 @@ public static void writeDouble1(Object o, int offset, double value) {

@Snippet
public static void writeDouble2(Object o, int offset, double value) {
Word.objectToTrackedPointer(o).writeDouble(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeDouble(Word.signed(offset), value, ID);
}

@Snippet
Expand All @@ -382,7 +381,7 @@ public static Object readObject1(Object o, int offset) {

@Snippet
public static Object readObject2(Object o, int offset) {
return Word.objectToTrackedPointer(o).readObject(WordFactory.signed(offset), ID);
return Word.objectToTrackedPointer(o).readObject(Word.signed(offset), ID);
}

@Snippet
Expand All @@ -397,7 +396,7 @@ public static void writeObject1(Object o, int offset, Object value) {

@Snippet
public static void writeObject2(Object o, int offset, Object value) {
Word.objectToTrackedPointer(o).writeObject(WordFactory.signed(offset), value, ID);
Word.objectToTrackedPointer(o).writeObject(Word.signed(offset), value, ID);
}

@Snippet
Expand Down
Loading

0 comments on commit 9f429e9

Please sign in to comment.