一、CAS相关
public final native boolean compareAndSwapObject(Object var1, long var2, Object var4, Object var5);
public final native boolean compareAndSwapInt(Object var1, long var2, int var4, int var5);
public final native boolean compareAndSwapLong(Object var1, long var2, long var4, long var6);
二、线程调度
这部分包括线程挂起、恢复、锁机制等方法
//取消阻塞线程
public native void unpark(Object var1);
//阻塞线程
public native void park(boolean var1, long var2);
//获得对象锁
/** @deprecated */
@Deprecated
public native void monitorEnter(Object var1);
//释放对象锁
/** @deprecated */
@Deprecated
public native void monitorExit(Object var1);
//尝试获取对象锁
/** @deprecated */
@Deprecated
public native boolean tryMonitorEnter(Object var1);
方法park、unpark即可实现线程的挂起与恢复,将一个线程进程挂起是通过park方法实现的,调用park方法后,线程将一直阻塞直到超时或中断等条件出现;unpark可以终止一个挂起的线程,使其恢复正常。
三、内存操作
//分配内存,相当于cpp的malloc函数
public native long allocateMemory(long var1);
//扩充内存
public native long reallocateMemory(long var1, long var3);
//释放内存
public native void freeMemory(long var1);
//在给定的内存块中设置值
public native void setMemory(Object var1, long var2, long var4, byte var6);
public void setMemory(long var1, long var3, byte var5) {
this.setMemory((Object)null, var1, var3, var5);
}
//内存拷贝
public native void copyMemory(Object var1, long var2, Object var4, long var5, long var7);
public void copyMemory(long var1, long var3, long var5) {
this.copyMemory((Object)null, var1, (Object)null, var3, var5);
}
//获取给定地址值,忽略修饰限定符的访问限制。与此类似操作还有: getInt,getDouble,getLong,getChar等
public native Object getObject(Object var1, long var2);
//为给定地址设置值,忽略修饰限定符的访问限制,与此类似操作还有: putInt,putDouble,putLong,putChar等
public native void putObject(Object var1, long var2, Object var4);