java-native-access / java-native-access/jna
Optimize GC behaviour
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.9k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
JNA is making an insane amount of garbage when I'm trying to find a fake process by name.
Here is a screenshot of the allocations (about 100k.sec)
http://i.stack.imgur.com/u3D2I.png
Here is the test case (used 4.3.0 SNAPSHOT of JNA)
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.Tlhelp32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
/**
* Created by Jonathan on 8/26/2016.
*/
public class Main {
public static void main(String[] args) {
while (true)
openProcess("doesntexist.exe");
}
private static final WinDef.DWORD DWORD_ZERO = new WinDef.DWORD(0);
private static final Tlhelp32.PROCESSENTRY32 entry = new Tlhelp32.PROCESSENTRY32.ByReference();
private static WinNT.HANDLE openProcess(String processName) {
WinNT.HANDLE snapshot = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL, DWORD_ZERO);
try {
while (Kernel32.INSTANCE.Process32Next(snapshot, entry)) {
String fileName = Native.toString(entry.szExeFile);
if (processName.equals(fileName))
return Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_ALL_ACCESS, true, entry.th32ProcessID.intValue());
}
} finally {
Kernel32.INSTANCE.CloseHandle(snapshot);
}
return null;
}
}
And finally here is the memory snapshot
https://dl.dropboxusercontent.com/u/91292881/ShareX/2016/08/JNA%204.3.0.snapshot
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Main reproduction and its Kernel32.INSTANCE CreateToolhelp32Snapshot, Process32Next, Native.toString, and CloseHandle calls. Run the loop while profiling allocations to identify the source of the garbage during a failed process lookup. Done means the same lookup behavior with materially lower allocation and GC activity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- operating-systems, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100