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-60402] Performance regression in PBKDF2WithHmacSHA256 on GraalVM 21 #10275

Open
gabrielmattar opened this issue Dec 9, 2024 · 1 comment
Assignees

Comments

@gabrielmattar
Copy link

gabrielmattar commented Dec 9, 2024

https://github.com/gabrielmattar/GR-60402

Describe the issue:

We are experiencing a noticeable slowdown in the execution of the PBKDF2WithHmacSHA256 algorithm in javax.crypto.SecretKeyFactory. This performance degradation began after upgrading from graalvm-jdk-17.0.13+10.1 to graalvm-jdk-21.0.5+9.1. The issue was observed on Linux x64, but not on macOS arm64. All VM versions were downloaded from the official GraalVM website and Oracle website.

Benchmark results on Linux x64:

| VM                           | Average (ms)      | Min (ms)      | Max (ms)      |
|------------------------------|-------------------|---------------|---------------|
| graalvm-jdk-17.0.13+10.1     | 1.99              | 1.42          | 3.63          |
| jdk-21.0.5                   | 2.05              | 1.63          | 3.08          |
| graalvm-jdk-21.0.5+9.1       | 42.02             | 1.75          | 83.77         |
| graalvm-jdk-23.0.1+11.1      | 28.72             | 1.74          | 87.31         |

Steps to reproduce the issue:

  1. Use the code below to benchmark the performance:
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.spec.KeySpec;

public final class Bench {
    public static void main(String[] args) {
        String secret = "mySecretPassword";
        byte[] salt = "randomSaltValue".getBytes();
        int iterations = 10000;
        int keyLength = 256; // in bits
        String algorithm = "PBKDF2WithHmacSHA256";
        String aesAlgorithm = "AES";

        int benchmarkIterations = 100;
        long startTime = System.nanoTime();

        for (int i = 0; i < benchmarkIterations; i++) {
            try {
                SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
                KeySpec spec = new PBEKeySpec(secret.toCharArray(), salt, iterations, keyLength);
                SecretKeySpec key = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), aesAlgorithm);
                key.getEncoded();
            } catch (Exception e) {
                System.err.println("Error during key generation: " + e.getMessage());
            }
        }

        long endTime = System.nanoTime();
        double averageTime = (endTime - startTime) / (double) benchmarkIterations;
        System.out.println("Average elapsed time: " + averageTime / 1_000_000 + " ms over " + benchmarkIterations + " iterations");
    }
}
  1. Run the benchmark with the following command:
java Bench.java

Describe GraalVM and your environment:

  • GraalVM version:
    java 21.0.5 2024-10-15 LTS
    Java(TM) SE Runtime Environment Oracle GraalVM 21.0.5+9.1 (build 21.0.5+9-LTS-jvmci-23.1-b48)
    Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.5+9.1 (build 21.0.5+9-LTS-jvmci-23.1-b48, mixed mode, sharing)
    
  • JDK major version: 21
  • OS: Ubuntu 24.04.1 LTS
  • Architecture: x86_64

More details
It was suggested in the GraalVM Slack to execute the code using the option -Dgraal.CompilationFailureAction=ExitVM, but it did not produce any logs. However, when adding -Dgraal.CompilationBailoutAsFailure=true, we received the following logs (both in GraalVM 17 and GraalVM 21).

Thread[JVMCI-native CompilerThread0,5,main]: Compilation of com.sun.crypto.provider.PBKDF2KeyImpl.deriveKey(Mac, byte[], byte[], int, int) @ 198 failed:
jdk.vm.ci.code.BailoutException: Code installation failed: dependencies failed
Failed dependency of type abstract_with_unique_concrete_subtype
  context = *sun.security.provider.DigestBase
  class   = sun.security.provider.SHA2$SHA256
  witness = sun.security.provider.SHA

	at [email protected]/jdk.vm.ci.hotspot.HotSpotCodeCacheProvider.installCode(HotSpotCodeCacheProvider.java:149)
	at jdk.internal.vm.compiler/org.graalvm.compiler.core.target.Backend.createInstalledCode(Backend.java:205)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask.installMethod(CompilationTask.java:439)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:204)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:109)
	at jdk.internal.vm.compiler/org.graalvm.compiler.core.CompilationWrapper.run(CompilationWrapper.java:224)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask.runCompilation(CompilationTask.java:407)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask.runCompilation(CompilationTask.java:380)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:159)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:681)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:110)
	at [email protected]/jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.compileMethod(HotSpotJVMCIRuntime.java:924)
If in an environment where setting system properties is possible, the following
properties are available to change compilation failure reporting:
- To disable compilation failure notifications, set CompilationFailureAction to Silent (e.g., -Dgraal.CompilationFailureAction=Silent).
- To print a message for a compilation failure without retrying the compilation, set CompilationFailureAction to Print (e.g., -Dgraal.CompilationFailureAction=Print).
Retrying compilation of com.sun.crypto.provider.PBKDF2KeyImpl.deriveKey(Mac, byte[], byte[], int, int) @ 198
Dumping IGV graphs in /home/gabriel/playground/benchCrypto/graal_dumps/2024.12.09.13.58.02.738/graal_diagnostics_140234@1/com.sun.crypto.provider.PBKDF2KeyImpl.deriveKey(Mac,_byte[],_byte[],_int,_int)_@_198

@fernando-valdez fernando-valdez self-assigned this Dec 10, 2024
@fernando-valdez fernando-valdez changed the title Performance regression in PBKDF2WithHmacSHA256 on GraalVM 21 [GR-60402] Performance regression in PBKDF2WithHmacSHA256 on GraalVM 21 Dec 10, 2024
@fernando-valdez
Copy link
Member

Hi @gabrielmattar, thanks for reporting this issue.
I was able to reproduce the issue locally, and created this ticket for internal tracking: GR-60402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants