com.threerings.util.unsafe
Class Unsafe

java.lang.Object
  extended by com.threerings.util.unsafe.Unsafe

public class Unsafe
extends Object

A native library for doing unsafe things. Don't use this library. If you must ignore that warning, then be sure you use it sparingly and only in very well considered cases.


Field Summary
protected static boolean _gcEnabled
          The current state of GC enablement.
protected static boolean _initialized
          Whether or not we were able to initialize our library (i.e. get access to jvmpi)
protected static boolean _loaded
          Whether or not we were able to load our library.
protected static Throwable _loadError
          The error that occurred when loading the native library, or null if none occurred or it was already reported.
 
Constructor Summary
Unsafe()
           
 
Method Summary
protected static void disableGC()
          Disables garbage collection.
protected static void enableGC()
          Reenable garbage collection after a call to disableGC().
protected static boolean init()
          Called to initialize our library.
protected static boolean isLoaded()
          Returns true if the native library was successfully loaded, and if this is the first time it's been checked and it failed, reports the failure.
protected static boolean nativeSetegid(int gid)
          Calls through to the native OS system call to change our egid.
protected static boolean nativeSeteuid(int uid)
          Calls through to the native OS system call to change our euid.
protected static boolean nativeSetgid(int gid)
          Calls through to the native OS system call to change our gid.
protected static boolean nativeSetuid(int uid)
          Calls through to the native OS system call to change our uid.
protected static void nativeSleep(int millis)
          Sleeps the current thread for the specified number of milliseconds.
static boolean setegid(int gid)
          Sets the process' effective gid to the specified value.
static boolean seteuid(int uid)
          Sets the process' effective uid to the specified value.
static void setGCEnabled(boolean enabled)
          Enables or disables garbage collection.
static boolean setgid(int gid)
          Sets the process' gid to the specified value.
static boolean setuid(int uid)
          Sets the process' uid to the specified value.
static void sleep(int millis)
          Causes the current thread to block for the specified number of milliseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_gcEnabled

protected static boolean _gcEnabled
The current state of GC enablement.


_loaded

protected static boolean _loaded
Whether or not we were able to load our library.


_initialized

protected static boolean _initialized
Whether or not we were able to initialize our library (i.e. get access to jvmpi)


_loadError

protected static Throwable _loadError
The error that occurred when loading the native library, or null if none occurred or it was already reported.

Constructor Detail

Unsafe

public Unsafe()
Method Detail

setGCEnabled

public static void setGCEnabled(boolean enabled)
Enables or disables garbage collection. Warning: you will be fucked if you leave it disabled for too long. Do not do this unless you are dang sure about what you're doing and are prepared to test your code on every platform this side of Nantucket.

Calls to this method do not nest. Regardless of how many times you disable GC, only one call is required to reenable it.


sleep

public static void sleep(int millis)
Causes the current thread to block for the specified number of milliseconds. This exists primarily to work around the fact that on Linux, Thread.sleep(long) is only accurate to around 12ms which is wholly unacceptable.


setuid

public static boolean setuid(int uid)
Sets the process' uid to the specified value.

Returns:
true if the uid was changed, false if we were unable to do so.

setgid

public static boolean setgid(int gid)
Sets the process' gid to the specified value.

Returns:
true if the gid was changed, false if we were unable to do so.

seteuid

public static boolean seteuid(int uid)
Sets the process' effective uid to the specified value.

Returns:
true if the euid was changed, false if we were unable to do so.

setegid

public static boolean setegid(int gid)
Sets the process' effective gid to the specified value.

Returns:
true if the egid was changed, false if we were unable to do so.

isLoaded

protected static boolean isLoaded()
Returns true if the native library was successfully loaded, and if this is the first time it's been checked and it failed, reports the failure.


enableGC

protected static void enableGC()
Reenable garbage collection after a call to disableGC().


disableGC

protected static void disableGC()
Disables garbage collection.


nativeSleep

protected static void nativeSleep(int millis)
Sleeps the current thread for the specified number of milliseconds.


nativeSetuid

protected static boolean nativeSetuid(int uid)
Calls through to the native OS system call to change our uid.


nativeSetgid

protected static boolean nativeSetgid(int gid)
Calls through to the native OS system call to change our gid.


nativeSeteuid

protected static boolean nativeSeteuid(int uid)
Calls through to the native OS system call to change our euid.


nativeSetegid

protected static boolean nativeSetegid(int gid)
Calls through to the native OS system call to change our egid.


init

protected static boolean init()
Called to initialize our library.