Skip to content

Commit

Permalink
masesgroup#542 (comment): implemented javap output prefill with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers committed Sep 25, 2024
1 parent 0fa01f4 commit 4fbfefa
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/net/JNetReflector/JNetReflectorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,45 @@ public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJav
si.Arguments = arguments;

process = Process.Start(si);
TimeSpan initial = process.TotalProcessorTime;
TimeSpan initialTotalProcessorTime = process.TotalProcessorTime;
int cycles = 0;
while ((exited = process.WaitForExit(100)) == false)
{
process.Refresh();
TimeSpan current = process.TotalProcessorTime;
if ((current - initial) < TimeSpan.FromMilliseconds(10)) break; // process is idle???
TimeSpan currentTotalProcessorTime = process.TotalProcessorTime;
if ((currentTotalProcessorTime - initialTotalProcessorTime) < TimeSpan.FromMilliseconds(10)) break; // process is idle???
if (++cycles > toBeAnalyzed.Count) break; // elapsed max cycles
}
if (exited && process.ExitCode != 0) throw new InvalidOperationException($"javap falied with error {process.ExitCode}");

List<string> lines = new();
bool foundParenthesis = false;
int cycleCounter = 0;
do
{
string line = process.StandardOutput.ReadLine();
if (line == null)
{
if (!foundParenthesis)
{
cycleCounter++;
System.Threading.Thread.Sleep(10);
continue;
}
else break;
}
else { lines.Add(line); cycleCounter = 0; }

if (line.TrimEnd() == "}") foundParenthesis = true;
}
while (!foundParenthesis || cycleCounter >= 100);

Dictionary<string, string> map = new Dictionary<string, string>();
string line;
int classCounter = -1;
string methodName = string.Empty;
string className = string.Empty;
bool nextLineIsDescriptor = false;
while ((line = process.StandardOutput.ReadLine()) != null)
foreach (var line in lines)
{
if (line.Contains("Compiled from"))
{
Expand Down

0 comments on commit 4fbfefa

Please sign in to comment.