I'm not aware of any way to find that out as an application. Even if it exists it will probably be a full system call and therefore prohibitively expensive to defensively do it everywhere.
Databases can do this via the page cache since that's basically an implementation of swapping where the DBMS has full control.
Edit: anyway, the problem in TA was that GC metadata had to be accessed. The GC cannot delay this. It might decide to abort the stop-the-world phase so the application can continue while GC metadata is swapped in, but then one runs into liveness issues since next time the GC runs it might already be swapped out again.