Skip to content

Commit

Permalink
Add a bunch of stuff to workaround sharing a JVM in a python process
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Jan 10, 2024
1 parent c1103b4 commit c7792fe
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pysoot/soot_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import faulthandler
import atexit
import os

import jpype
Expand All @@ -8,8 +10,17 @@

from pysoot.sootir.soot_class import SootClass

jpype.addClassPath(os.path.join(os.path.dirname(__file__), "soot-trunk.jar"))
jpype.startJVM("-Xmx2G")

def startJVM():
if jpype.isJVMStarted():
return
jpype.addClassPath(os.path.join(os.path.dirname(__file__), "soot-trunk.jar"))
jpype.startJVM("-Xmx2G")
faulthandler.enable()
faulthandler.disable()
os.register_at_fork(before=jpype.shutdownJVM)
atexit.register(jpype.shutdownJVM)


class SootManager:
def __init__(self, java_heap_size: int | None = None):
Expand All @@ -18,6 +29,7 @@ def __init__(self, java_heap_size: int | None = None):
self.java_heap_size = int(psutil.virtual_memory().total*0.75)
else:
self.java_heap_size = java_heap_size
startJVM()


def init(self, main_class, input_file, input_format: str, android_sdk: str | None, soot_classpath: str | None, ir_format: str):
Expand Down

0 comments on commit c7792fe

Please sign in to comment.