Skip to content

Detecting JIT at runtime

Zeex edited this page Sep 10, 2014 · 7 revisions

Starting from version 1.2 it is possible to detect if the script is running under the JIT with the lctrl 7 instruction:

#include <a_samp>

stock bool:IsJITPresent() {
	// If running under the JIT "lctrl 7" will set pri to 1, otherwise it
	// will act as a no-op.
	#emit zero.pri
	#emit lctrl 7
	#emit retn
	return false;
}

main() {
	printf("JIT is %spresent", IsJitPresent() ? ("") : ("not "));
}

It can also be done with the OnJITCompile() callback introduced in JIT 2.0:

public OnJITCompile() {
	// You're being JIT-compiled, return 1 if you're OK with that
	// and 0 otherwise.
	return 1;
}
Clone this wiki locally