Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-60548] Cleanly separate word box types by class loader. #10364

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public static void runTest(InvariantsTool tool) {
verifiers.add(new VerifyVirtualizableUsage());
verifiers.add(new VerifyUpdateUsages());
verifiers.add(new VerifyLibGraalContextChecks());
verifiers.add(new VerifyWordFactoryUsage());
verifiers.add(new VerifyBailoutUsage());
verifiers.add(new VerifySystemPropertyUsage());
verifiers.add(new VerifyInstanceOfUsage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.graal.compiler.core.test;

import jdk.graal.compiler.nodes.StructuredGraph;
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
import jdk.graal.compiler.nodes.spi.CoreProviders;
import jdk.graal.compiler.phases.VerifyPhase;
import jdk.graal.compiler.word.Word;
import jdk.vm.ci.meta.ResolvedJavaType;
import org.graalvm.word.WordFactory;

/**
* 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> {

@Override
public boolean checkContract() {
return false;
}

@Override
protected void verify(StructuredGraph graph, CoreProviders context) {

ResolvedJavaType wordFactory = context.getMetaAccess().lookupJavaType(WordFactory.class);
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
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)"),
Word.class.getName(),
graph.method().format("%n(%p)"));

}
}
}
}
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 org.graalvm.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 org.graalvm.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