Skip to content

Commit

Permalink
[GR-24398] Eliminate MethodSubstitutions
Browse files Browse the repository at this point in the history
PullRequest: graal/10824
  • Loading branch information
tkrodriguez committed Feb 15, 2022
2 parents 09f7a62 + 604d98e commit 9fe1533
Show file tree
Hide file tree
Showing 70 changed files with 802 additions and 4,330 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ public final class GraalOptions {
@Option(help = "Use Graal-generated stubs for complicated LIR operations instead of embedding all the emitted code.", type = OptionType.Expert)
public static final OptionKey<Boolean> UseGraalStubs = new OptionKey<>(true);

@Option(help = "Encode and decode snippets and substitutions before parsing to test libgraal code path. This option is ignored in the context of libgraal.")
public static final OptionKey<Boolean> UseEncodedGraphs = new OptionKey<>(false);

@Option(help = "If applicable, use bulk zeroing instructions when the zeroing size in bytes exceeds this threshold.", type = OptionType.Expert)
public static final OptionKey<Integer> MinimalBulkZeroingSize = new OptionKey<>(2048);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.graalvm.compiler.api.replacements.MethodSubstitution;
import org.graalvm.compiler.api.replacements.Snippet;
import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
import org.graalvm.compiler.api.replacements.Snippet.NonNullParameter;
Expand Down Expand Up @@ -424,7 +423,7 @@ public static void runTest(InvariantsTool tool) {
if (matches(filters, methodName)) {
executor.execute(() -> {
try (DebugContext debug = new Builder(options).build()) {
boolean isSubstitution = method.getAnnotation(Snippet.class) != null || method.getAnnotation(MethodSubstitution.class) != null;
boolean isSubstitution = method.getAnnotation(Snippet.class) != null;
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).setIsSubstitution(isSubstitution).build();
try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
checkMethod(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,34 @@
*/
package org.graalvm.compiler.hotspot.test;

import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA2_IMPL_COMPRESS_MB;
import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA5_IMPL_COMPRESS_MB;
import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA_IMPL_COMPRESS_MB;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.AlgorithmParameters;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallDescriptor;
import org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
import org.graalvm.compiler.replacements.SnippetSubstitutionNode;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import jdk.vm.ci.code.BailoutException;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.meta.ResolvedJavaMethod;

/**
* Tests the intrinsification of certain crypto methods.
Expand Down Expand Up @@ -172,4 +184,74 @@ public Result runEncryptDecrypt(SecretKey key, String algorithm) throws Exceptio
return new Result(null, e);
}
}

@Test
public void testDigestBaseSHA() throws Exception {
Assume.assumeTrue("SHA1 not supported", runtime().getVMConfig().useSHA1Intrinsics());
testDigestBase("sun.security.provider.DigestBase", "implCompressMultiBlock", "SHA-1", SHA_IMPL_COMPRESS_MB);
}

@Test
public void testDigestBaseSHA2() throws Exception {
Assume.assumeTrue("SHA256 not supported", runtime().getVMConfig().useSHA256Intrinsics());
testDigestBase("sun.security.provider.DigestBase", "implCompressMultiBlock", "SHA-256", SHA2_IMPL_COMPRESS_MB);
}

@Test
public void testDigestBaseSHA5() throws Exception {
Assume.assumeTrue("SHA512 not supported", runtime().getVMConfig().useSHA512Intrinsics());
testDigestBase("sun.security.provider.DigestBase", "implCompressMultiBlock", "SHA-512", SHA5_IMPL_COMPRESS_MB);
}

@Before
public void clearExceptionCall() {
expectedCall = null;
}

HotSpotForeignCallDescriptor expectedCall;

@Override
protected void checkLowTierGraph(StructuredGraph graph) {
if (expectedCall != null) {
for (ForeignCallNode node : graph.getNodes().filter(ForeignCallNode.class)) {
if (node.getDescriptor() == expectedCall) {
return;
}
}
assertTrue("expected call to " + expectedCall, false);
}
}

private void testDigestBase(String className, String methodName, String algorithm, HotSpotForeignCallDescriptor call) throws Exception {
Class<?> klass = Class.forName(className);
expectedCall = call;
MessageDigest digest = MessageDigest.getInstance(algorithm);
byte[] expected = digest.digest(input.clone());
ResolvedJavaMethod method = getResolvedJavaMethod(klass, methodName);

try {
testDigestBase(digest, expected, method);
} catch (BailoutException e) {
// The plugin may cause loading which invalidates assumptions in the graph so retry it
// once. This normally only occurs when running individual tests.
if (e.getMessage().contains("Code installation failed: dependencies failed")) {
testDigestBase(digest, expected, method);
} else {
throw e;
}
}
}

private void testDigestBase(MessageDigest digest, byte[] expected, ResolvedJavaMethod method) {
StructuredGraph graph = parseForCompile(method);
assertTrue(graph.getNodes().filter(SnippetSubstitutionNode.class).isNotEmpty());
InstalledCode intrinsic = getCode(method, graph, false, true, getInitialOptions());
try {
Assert.assertNotNull("missing intrinsic", intrinsic);
byte[] actual = digest.digest(input.clone());
assertDeepEquals(expected, actual);
} finally {
intrinsic.invalidate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
import java.lang.invoke.MethodType;

import org.graalvm.compiler.api.directives.GraalDirectives;
import org.graalvm.compiler.api.replacements.MethodSubstitution;
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
import org.graalvm.compiler.hotspot.HotSpotBackend;
import org.graalvm.compiler.nodes.IfNode;
import org.graalvm.compiler.replacements.test.MethodSubstitutionTest;
import org.junit.Test;

/**
* Tests HotSpot specific {@link MethodSubstitution}s.
* Tests HotSpot specific substitutions.
*/
public class HotSpotMethodSubstitutionTest extends MethodSubstitutionTest {

Expand Down
Loading

0 comments on commit 9fe1533

Please sign in to comment.