I was wondering if it is possible to prevent an object from being moved around by the GC by setting one of the bits in the mark word of the object header myself (trying to trick GC).
So basically I would like to know if this way it could be ensured that a marked object always has the same memory address.
No, HotSpot JVM does not support object pinning in any form, even internally inside JVM.
Do not try to modify object header. It is high chance JVM will crash otherwise. The contents of the header may vary depending on JVM version, arguments and selected GC algorithm. JVM has full control over the object header and is not ready for external changes.