From e6ac1351cb51c362e0911f5335471ee27cec045d Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Wed, 28 Apr 2021 21:21:58 -0700 Subject: [PATCH 1/6] TypeScriptVisitor init must be manually called (prevent memory leaks) --- .../felixgrund/codeshovel/parser/impl/TypeScriptParser.java | 1 + .../felixgrund/codeshovel/visitors/TypeScriptVisitor.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/felixgrund/codeshovel/parser/impl/TypeScriptParser.java b/src/main/java/com/felixgrund/codeshovel/parser/impl/TypeScriptParser.java index 994a5ec08..2e4d42d33 100644 --- a/src/main/java/com/felixgrund/codeshovel/parser/impl/TypeScriptParser.java +++ b/src/main/java/com/felixgrund/codeshovel/parser/impl/TypeScriptParser.java @@ -91,6 +91,7 @@ private abstract class TypeScriptMethodVisitor extends TypeScriptVisitor { @Override public void visit(String source) { + init(); sourceFile = getSource(source); visit(sourceFile); sourceFile = null; diff --git a/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java b/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java index 6fce8cc92..f5ca766f5 100644 --- a/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java +++ b/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java @@ -17,10 +17,10 @@ public class TypeScriptVisitor { public TypeScriptVisitor() { ts = TypeScript.getInstance().getTS(); - init(); } public void visit(String source) { + init(); visit(getSource(source)); clear(); } @@ -44,14 +44,13 @@ protected V8Object getSource(String source) { return ts.executeObjectFunction("createSourceFile", parameters); } - private void init() { + protected void init() { scope = new MemoryManager(TypeScript.getInstance().getRuntime()); syntaxKind = ts.getObject("SyntaxKind"); } protected void clear() { scope.release(); - init(); } protected void visit(V8Object node) { From c516e4448529d6b493c8f2f0fd124d23039b6d07 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Wed, 28 Apr 2021 21:40:38 -0700 Subject: [PATCH 2/6] Release V8 lock to other threads --- .../com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java b/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java index f5ca766f5..607ffaa38 100644 --- a/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java +++ b/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java @@ -12,6 +12,7 @@ public class TypeScriptVisitor { protected final V8Object ts; private V8Object syntaxKind; private MemoryManager scope; + private V8Locker locker; private static final Map syntaxKindCache = new HashMap(); @@ -51,6 +52,7 @@ protected void init() { protected void clear() { scope.release(); + locker.release(); } protected void visit(V8Object node) { From ba04bac895f150ad63c9951ba06db701e4a43a23 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Wed, 28 Apr 2021 21:59:15 -0700 Subject: [PATCH 3/6] Revert "Release V8 lock to other threads" This reverts commit c516e4448529d6b493c8f2f0fd124d23039b6d07. --- .../com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java b/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java index 607ffaa38..f5ca766f5 100644 --- a/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java +++ b/src/main/java/com/felixgrund/codeshovel/visitors/TypeScriptVisitor.java @@ -12,7 +12,6 @@ public class TypeScriptVisitor { protected final V8Object ts; private V8Object syntaxKind; private MemoryManager scope; - private V8Locker locker; private static final Map syntaxKindCache = new HashMap(); @@ -52,7 +51,6 @@ protected void init() { protected void clear() { scope.release(); - locker.release(); } protected void visit(V8Object node) { From ef95dd8ba383a0157d062d84e916726af60990b7 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Wed, 28 Apr 2021 22:01:58 -0700 Subject: [PATCH 4/6] Replace TS instance if multithreaded --- src/main/java/com/felixgrund/codeshovel/util/TypeScript.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/felixgrund/codeshovel/util/TypeScript.java b/src/main/java/com/felixgrund/codeshovel/util/TypeScript.java index 7a2b18bc1..db43bdaa0 100644 --- a/src/main/java/com/felixgrund/codeshovel/util/TypeScript.java +++ b/src/main/java/com/felixgrund/codeshovel/util/TypeScript.java @@ -17,12 +17,15 @@ public class TypeScript { private static TypeScript instance; private final NodeJS nodeJS; private static V8Object ts; + private static Thread thread; private static Logger log = LoggerFactory.getLogger(TypeScript.class); public static TypeScript getInstance() { - if (instance == null) { + Thread currentThread = Thread.currentThread(); + if (instance == null || thread != currentThread) { try { + thread = currentThread; instance = new TypeScript(); } catch (IOException e) { e.printStackTrace(); From 968ddfaa97727e2f69e81e27bd73d9f71c554e9b Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Tue, 7 Jun 2022 14:34:35 -0700 Subject: [PATCH 5/6] Use linux version of J2V8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bcb1f7325..d10658775 100755 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 5.7.0 1.7.0 8803cbe8aca1b3b6ebf73e13f5c41665f393b381 - j2v8_macosx_x86_64 + j2v8_linux_x86_64 From 3749882912d0af8cb30d85aacf86e61850d2647b Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Tue, 7 Jun 2022 14:43:59 -0700 Subject: [PATCH 6/6] Bump J2V8 version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d10658775..3d0b1498b 100755 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ com.eclipsesource.j2v8 ${j2v8.artifactId} - 4.6.0 + 4.8.0