From c89519e0665c360a4a949d752314edb32a74158c Mon Sep 17 00:00:00 2001
From: stepan <stepan.sindelar@oracle.com>
Date: Mon, 19 Feb 2018 18:48:17 +0100
Subject: [PATCH] Make MessageDigest in RDeparse thread local

---
 .../src/com/oracle/truffle/r/runtime/RDeparse.java            | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
index 4c065da548..49ca414bb9 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java
@@ -350,7 +350,7 @@ public class RDeparse {
             }
         }
 
-        private static MessageDigest digest = null;
+        private static ThreadLocal<MessageDigest> digestTheadLocal = new ThreadLocal<>();
 
         private Path emitToFile(String qualifiedFunctionName, String deparsePath) throws IOException, NoSuchAlgorithmException {
             Path tmpDir = Paths.get(deparsePath);
@@ -358,8 +358,10 @@ public class RDeparse {
 
             Path path;
             if (FastROptions.EmitTmpHashed.getBooleanValue()) {
+                MessageDigest digest = digestTheadLocal.get();
                 if (digest == null) {
                     digest = MessageDigest.getInstance("SHA-256");
+                    digestTheadLocal.set(digest);
                 }
                 String printHexBinary = Utils.toHexString(digest.digest(sb.toString().getBytes()));
                 assert printHexBinary.length() > 10;
-- 
GitLab