mirror of
https://github.com/wassname/ray.git
synced 2026-07-24 13:20:22 +08:00
[Java] Fix out-dated signatures of JNI methods (#2756)
1) Renamed the native JNI methods and some parameters of JNI methods. 2) Fixed native JNI methods' signatures by `javah` tool. 3) Removed some useless native methods.
This commit is contained in:
@@ -11,7 +11,7 @@ public interface LocalSchedulerLink {
|
||||
|
||||
void submitTask(TaskSpec task);
|
||||
|
||||
TaskSpec getTaskTodo();
|
||||
TaskSpec getTask();
|
||||
|
||||
void markTaskPutDependency(UniqueID taskId, UniqueID objectId);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public class LocalSchedulerProxy {
|
||||
}
|
||||
|
||||
public TaskSpec getTask() {
|
||||
TaskSpec ts = scheduler.getTaskTodo();
|
||||
TaskSpec ts = scheduler.getTask();
|
||||
RayLog.core.info("Task " + ts.taskId.toString() + " received");
|
||||
return ts;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class MockLocalScheduler implements LocalSchedulerLink {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskSpec getTaskTodo() {
|
||||
public TaskSpec getTask() {
|
||||
throw new RuntimeException("invalid execution flow here");
|
||||
}
|
||||
|
||||
|
||||
@@ -114,10 +114,8 @@ public class RayNativeRuntime extends RayRuntime {
|
||||
LocalSchedulerLink slink = new DefaultLocalSchedulerClient(
|
||||
params.local_scheduler_name,
|
||||
WorkerContext.currentWorkerId(),
|
||||
UniqueID.NIL,
|
||||
isWorker,
|
||||
WorkerContext.currentTask().taskId,
|
||||
0,
|
||||
false
|
||||
);
|
||||
|
||||
@@ -133,10 +131,8 @@ public class RayNativeRuntime extends RayRuntime {
|
||||
LocalSchedulerLink slink = new DefaultLocalSchedulerClient(
|
||||
params.raylet_socket_name,
|
||||
WorkerContext.currentWorkerId(),
|
||||
UniqueID.NIL,
|
||||
isWorker,
|
||||
WorkerContext.currentTask().taskId,
|
||||
0,
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
+51
-42
@@ -32,31 +32,17 @@ public class DefaultLocalSchedulerClient implements LocalSchedulerLink {
|
||||
boolean useRaylet = false;
|
||||
|
||||
public DefaultLocalSchedulerClient(String schedulerSockName, UniqueID clientId,
|
||||
UniqueID actorId, boolean isWorker, UniqueID driverId,
|
||||
long numGpus, boolean useRaylet) {
|
||||
client = _init(schedulerSockName, clientId.getBytes(), actorId.getBytes(), isWorker,
|
||||
driverId.getBytes(), numGpus, useRaylet);
|
||||
boolean isWorker, UniqueID driverId, boolean useRaylet) {
|
||||
client = nativeInit(schedulerSockName, clientId.getBytes(),
|
||||
isWorker, driverId.getBytes(), useRaylet);
|
||||
this.useRaylet = useRaylet;
|
||||
}
|
||||
|
||||
private static native long _init(String localSchedulerSocket, byte[] workerId,
|
||||
byte[] actorId, boolean isWorker, byte[] driverTaskId,
|
||||
long numGpus, boolean useRaylet);
|
||||
|
||||
private static native byte[] _computePutId(long client, byte[] taskId, int putIndex);
|
||||
|
||||
private static native byte[] _generateTaskId(byte[] driverId, byte[] parentTaskId, int taskIndex);
|
||||
|
||||
private static native void _task_done(long client);
|
||||
|
||||
private static native boolean[] _waitObject(long conn, byte[][] objectIds,
|
||||
int numReturns, int timeout, boolean waitLocal);
|
||||
|
||||
@Override
|
||||
public List<byte[]> wait(byte[][] objectIds, int timeoutMs, int numReturns) {
|
||||
assert (useRaylet == true);
|
||||
|
||||
boolean[] readys = _waitObject(client, objectIds, numReturns, timeoutMs, false);
|
||||
boolean[] readys = nativeWaitObject(client, objectIds, numReturns, timeoutMs, false);
|
||||
assert (readys.length == objectIds.length);
|
||||
|
||||
List<byte[]> ret = new ArrayList<>();
|
||||
@@ -91,12 +77,12 @@ public class DefaultLocalSchedulerClient implements LocalSchedulerLink {
|
||||
a = task.cursorId.getBytes();
|
||||
}
|
||||
|
||||
_submitTask(client, a, info, info.position(), info.remaining(), useRaylet);
|
||||
nativeSubmitTask(client, a, info, info.position(), info.remaining(), useRaylet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskSpec getTaskTodo() {
|
||||
byte[] bytes = _getTaskTodo(client, useRaylet);
|
||||
public TaskSpec getTask() {
|
||||
byte[] bytes = nativeGetTask(client, useRaylet);
|
||||
assert (null != bytes);
|
||||
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
return taskInfo2Spec(bb);
|
||||
@@ -104,14 +90,14 @@ public class DefaultLocalSchedulerClient implements LocalSchedulerLink {
|
||||
|
||||
@Override
|
||||
public void markTaskPutDependency(UniqueID taskId, UniqueID objectId) {
|
||||
_put_object(client, taskId.getBytes(), objectId.getBytes());
|
||||
nativePutObject(client, taskId.getBytes(), objectId.getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstructObject(UniqueID objectId, boolean fetchOnly) {
|
||||
List<UniqueID> objects = new ArrayList<>();
|
||||
objects.add(objectId);
|
||||
_reconstruct_objects(client, getIdBytes(objects), fetchOnly);
|
||||
nativeReconstructObjects(client, getIdBytes(objects), fetchOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,30 +106,20 @@ public class DefaultLocalSchedulerClient implements LocalSchedulerLink {
|
||||
RayLog.core.info("Reconstructing objects for task {}, object IDs are {}",
|
||||
UniqueIdHelper.computeTaskId(objectIds.get(0)), objectIds);
|
||||
}
|
||||
_reconstruct_objects(client, getIdBytes(objectIds), fetchOnly);
|
||||
nativeReconstructObjects(client, getIdBytes(objectIds), fetchOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniqueID generateTaskId(UniqueID driverId, UniqueID parentTaskId, int taskIndex) {
|
||||
byte[] bytes = _generateTaskId(driverId.getBytes(), parentTaskId.getBytes(), taskIndex);
|
||||
byte[] bytes = nativeGenerateTaskId(driverId.getBytes(), parentTaskId.getBytes(), taskIndex);
|
||||
return new UniqueID(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyUnblocked() {
|
||||
_notify_unblocked(client);
|
||||
nativeNotifyUnblocked(client);
|
||||
}
|
||||
|
||||
private static native void _notify_unblocked(long client);
|
||||
|
||||
private static native void _reconstruct_objects(long client, byte[][] objectIds,
|
||||
boolean fetchOnly);
|
||||
|
||||
private static native void _put_object(long client, byte[] taskId, byte[] objectId);
|
||||
|
||||
// return TaskInfo (in FlatBuffer)
|
||||
private static native byte[] _getTaskTodo(long client, boolean useRaylet);
|
||||
|
||||
public static TaskSpec taskInfo2Spec(ByteBuffer bb) {
|
||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
TaskInfo info = TaskInfo.getRootAsTaskInfo(bb);
|
||||
@@ -282,10 +258,6 @@ public class DefaultLocalSchedulerClient implements LocalSchedulerLink {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// task -> TaskInfo (with FlatBuffer)
|
||||
protected static native void _submitTask(long client, byte[] cursorId, /*Direct*/ByteBuffer task,
|
||||
int pos, int sz, boolean useRaylet);
|
||||
|
||||
private static byte[][] getIdBytes(List<UniqueID> objectIds) {
|
||||
int size = objectIds.size();
|
||||
byte[][] ids = new byte[size][];
|
||||
@@ -296,8 +268,45 @@ public class DefaultLocalSchedulerClient implements LocalSchedulerLink {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
_destroy(client);
|
||||
nativeDestroy(client);
|
||||
}
|
||||
|
||||
private static native void _destroy(long client);
|
||||
|
||||
/// Native method declarations.
|
||||
///
|
||||
/// If you change the signature of any native methods, please re-generate
|
||||
/// the C++ header file and update the C++ implementation accordingly:
|
||||
///
|
||||
/// Suppose that $Dir is your ray root directory.
|
||||
/// 1) pushd $Dir/java/runtime-native/target/classes
|
||||
/// 2) javah -classpath .:$Dir/java/runtime-common/target/classes/:$Dir/java/api/target/classes/
|
||||
/// org.ray.spi.impl.DefaultLocalSchedulerClient
|
||||
/// 3) cp org_ray_spi_impl_DefaultLocalSchedulerClient.h $Dir/src/local_scheduler/lib/java/
|
||||
/// 4) vim $Dir/src/local_scheduler/lib/java/org_ray_spi_impl_DefaultLocalSchedulerClient.cc
|
||||
/// 5) popd
|
||||
|
||||
private static native long nativeInit(String localSchedulerSocket, byte[] workerId,
|
||||
boolean isWorker, byte[] driverTaskId, boolean useRaylet);
|
||||
|
||||
private static native void nativeSubmitTask(long client, byte[] cursorId, ByteBuffer taskBuff,
|
||||
int pos, int taskSize, boolean useRaylet);
|
||||
|
||||
// return TaskInfo (in FlatBuffer)
|
||||
private static native byte[] nativeGetTask(long client, boolean useRaylet);
|
||||
|
||||
private static native void nativeDestroy(long client);
|
||||
|
||||
private static native void nativeReconstructObjects(long client, byte[][] objectIds,
|
||||
boolean fetchOnly);
|
||||
|
||||
private static native void nativeNotifyUnblocked(long client);
|
||||
|
||||
private static native void nativePutObject(long client, byte[] taskId, byte[] objectId);
|
||||
|
||||
private static native boolean[] nativeWaitObject(long conn, byte[][] objectIds,
|
||||
int numReturns, int timeout, boolean waitLocal);
|
||||
|
||||
private static native byte[] nativeGenerateTaskId(byte[] driverId, byte[] parentTaskId,
|
||||
int taskIndex);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,22 +33,19 @@ class UniqueIdFromJByteArray {
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _init
|
||||
* Signature: (Ljava/lang/String;[B[BZJ)J
|
||||
* Method: nativeInit
|
||||
* Signature: (Ljava/lang/String;[BZ[BZ)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1init(JNIEnv *env,
|
||||
jclass,
|
||||
jstring sockName,
|
||||
jbyteArray wid,
|
||||
jbyteArray actorId,
|
||||
jboolean isWorker,
|
||||
jbyteArray driverId,
|
||||
jlong numGpus,
|
||||
jboolean useRaylet) {
|
||||
// native private static long _init(String localSchedulerSocket,
|
||||
// byte[] workerId, byte[] actorId, boolean isWorker, long numGpus);
|
||||
UniqueIdFromJByteArray worker_id(env, wid);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeInit(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jstring sockName,
|
||||
jbyteArray workerId,
|
||||
jboolean isWorker,
|
||||
jbyteArray driverId,
|
||||
jboolean useRaylet) {
|
||||
UniqueIdFromJByteArray worker_id(env, workerId);
|
||||
UniqueIdFromJByteArray driver_id(env, driverId);
|
||||
const char *nativeString = env->GetStringUTFChars(sockName, JNI_FALSE);
|
||||
auto client =
|
||||
@@ -60,23 +57,20 @@ Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1init(JNIEnv *env,
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _submitTask
|
||||
* Signature: (JLjava/nio/ByteBuffer;II)V
|
||||
* Method: nativeSubmitTask
|
||||
* Signature: (J[BLjava/nio/ByteBuffer;IIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1submitTask(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeSubmitTask(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jlong c,
|
||||
jlong client,
|
||||
jbyteArray cursorId,
|
||||
jobject buff,
|
||||
jobject taskBuff,
|
||||
jint pos,
|
||||
jint sz,
|
||||
jint taskSize,
|
||||
jboolean useRaylet) {
|
||||
// task -> TaskInfo (with FlatBuffer)
|
||||
// native private static void _submitTask(long client, /*Direct*/ByteBuffer
|
||||
// task);
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
|
||||
std::vector<ObjectID> execution_dependencies;
|
||||
if (cursorId != nullptr) {
|
||||
@@ -85,37 +79,36 @@ Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1submitTask(
|
||||
}
|
||||
if (!useRaylet) {
|
||||
TaskSpec *task =
|
||||
reinterpret_cast<char *>(env->GetDirectBufferAddress(buff)) + pos;
|
||||
reinterpret_cast<char *>(env->GetDirectBufferAddress(taskBuff)) + pos;
|
||||
TaskExecutionSpec taskExecutionSpec =
|
||||
TaskExecutionSpec(execution_dependencies, task, sz);
|
||||
local_scheduler_submit(client, taskExecutionSpec);
|
||||
TaskExecutionSpec(execution_dependencies, task, taskSize);
|
||||
local_scheduler_submit(conn, taskExecutionSpec);
|
||||
} else {
|
||||
auto data =
|
||||
reinterpret_cast<char *>(env->GetDirectBufferAddress(buff)) + pos;
|
||||
ray::raylet::TaskSpecification task_spec(std::string(data, sz));
|
||||
local_scheduler_submit_raylet(client, execution_dependencies, task_spec);
|
||||
reinterpret_cast<char *>(env->GetDirectBufferAddress(taskBuff)) + pos;
|
||||
ray::raylet::TaskSpecification task_spec(std::string(data, taskSize));
|
||||
local_scheduler_submit_raylet(conn, execution_dependencies, task_spec);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _getTaskTodo
|
||||
* Signature: (J)[B
|
||||
* Method: nativeGetTask
|
||||
* Signature: (JZ)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1getTaskTodo(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeGetTask(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jlong c,
|
||||
jlong client,
|
||||
jboolean useRaylet) {
|
||||
// native private static ByteBuffer _getTaskTodo(long client);
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
int64_t task_size = 0;
|
||||
|
||||
// TODO: handle actor failure later
|
||||
TaskSpec *spec = !useRaylet
|
||||
? local_scheduler_get_task(client, &task_size)
|
||||
: local_scheduler_get_task_raylet(client, &task_size);
|
||||
? local_scheduler_get_task(conn, &task_size)
|
||||
: local_scheduler_get_task_raylet(conn, &task_size);
|
||||
|
||||
jbyteArray result;
|
||||
result = env->NewByteArray(task_size);
|
||||
@@ -133,166 +126,122 @@ Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1getTaskTodo(
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _computePutId
|
||||
* Signature: (J[BI)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1computePutId(JNIEnv *env,
|
||||
jclass,
|
||||
jlong c,
|
||||
jbyteArray tid,
|
||||
jint index) {
|
||||
// native private static byte[] _computePutId(long client, byte[] taskId, int
|
||||
// putIndex);
|
||||
UniqueIdFromJByteArray task(env, tid);
|
||||
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
ObjectID putId = task_compute_put_id(*task.PID, index);
|
||||
local_scheduler_put_object(client, *task.PID, putId);
|
||||
|
||||
jbyteArray result;
|
||||
result = env->NewByteArray(sizeof(ObjectID));
|
||||
if (result == nullptr) {
|
||||
return nullptr; /* out of memory error thrown */
|
||||
}
|
||||
|
||||
// move from task spec structure to the java structure
|
||||
env->SetByteArrayRegion(result, 0, sizeof(ObjectID),
|
||||
reinterpret_cast<jbyte *>(&putId));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _destroy
|
||||
* Method: nativeDestroy
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1destroy(JNIEnv *,
|
||||
jclass,
|
||||
jlong c) {
|
||||
// native private static void _destroy(long client);
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
local_scheduler_disconnect_client(client);
|
||||
LocalSchedulerConnection_free(client);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeDestroy(JNIEnv *,
|
||||
jclass,
|
||||
jlong client) {
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
local_scheduler_disconnect_client(conn);
|
||||
LocalSchedulerConnection_free(conn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _task_done
|
||||
* Signature: (J)V
|
||||
* Method: nativeReconstructObjects
|
||||
* Signature: (J[[BZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1task_1done(JNIEnv *,
|
||||
jclass,
|
||||
jlong c) {
|
||||
// native private static void _task_done(long client);
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
local_scheduler_task_done(client);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _reconstruct_objects
|
||||
* Signature: (J[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1reconstruct_1objects(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeReconstructObjects(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jlong c,
|
||||
jobjectArray oids,
|
||||
jboolean fetch_only) {
|
||||
// native private static void _reconstruct_objects(long client, byte[][]
|
||||
// objectIds, boolean fetchOnly);
|
||||
|
||||
jlong client,
|
||||
jobjectArray objectIds,
|
||||
jboolean fetchOnly) {
|
||||
std::vector<ObjectID> object_ids;
|
||||
auto len = env->GetArrayLength(oids);
|
||||
auto len = env->GetArrayLength(objectIds);
|
||||
for (int i = 0; i < len; i++) {
|
||||
jbyteArray oid = (jbyteArray) env->GetObjectArrayElement(oids, i);
|
||||
UniqueIdFromJByteArray o(env, oid);
|
||||
object_ids.push_back(*o.PID);
|
||||
env->DeleteLocalRef(oid);
|
||||
jbyteArray object_id_bytes =
|
||||
static_cast<jbyteArray>(env->GetObjectArrayElement(objectIds, i));
|
||||
UniqueIdFromJByteArray object_id(env, object_id_bytes);
|
||||
object_ids.push_back(*object_id.PID);
|
||||
env->DeleteLocalRef(object_id_bytes);
|
||||
}
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
local_scheduler_reconstruct_objects(client, object_ids, fetch_only);
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
local_scheduler_reconstruct_objects(conn, object_ids, fetchOnly);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _notify_unblocked
|
||||
* Method: nativeNotifyUnblocked
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1notify_1unblocked(JNIEnv *,
|
||||
jclass,
|
||||
jlong c) {
|
||||
// native private static void _notify_unblocked(long client);
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
local_scheduler_notify_unblocked(client);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeNotifyUnblocked(
|
||||
JNIEnv *,
|
||||
jclass,
|
||||
jlong client) {
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
local_scheduler_notify_unblocked(conn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _put_object
|
||||
* Method: nativePutObject
|
||||
* Signature: (J[B[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1put_1object(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativePutObject(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jlong c,
|
||||
jbyteArray tid,
|
||||
jbyteArray oid) {
|
||||
// native private static void _put_object(long client, byte[] taskId, byte[]
|
||||
// objectId);
|
||||
UniqueIdFromJByteArray o(env, oid), t(env, tid);
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
local_scheduler_put_object(client, *t.PID, *o.PID);
|
||||
jlong client,
|
||||
jbyteArray taskId,
|
||||
jbyteArray objectId) {
|
||||
UniqueIdFromJByteArray object_id(env, objectId), task_id(env, taskId);
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
local_scheduler_put_object(conn, *task_id.PID, *object_id.PID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: nativeWaitObject
|
||||
* Signature: (J[[BIIZ)[Z
|
||||
*/
|
||||
JNIEXPORT jbooleanArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1waitObject(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeWaitObject(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jlong c,
|
||||
jobjectArray oids,
|
||||
jint num_returns,
|
||||
jint timeout_ms,
|
||||
jboolean wait_local) {
|
||||
jlong client,
|
||||
jobjectArray objectIds,
|
||||
jint numReturns,
|
||||
jint timeoutMillis,
|
||||
jboolean isWaitLocal) {
|
||||
std::vector<ObjectID> object_ids;
|
||||
auto len = env->GetArrayLength(oids);
|
||||
auto len = env->GetArrayLength(objectIds);
|
||||
for (int i = 0; i < len; i++) {
|
||||
jbyteArray oid = (jbyteArray) env->GetObjectArrayElement(oids, i);
|
||||
UniqueIdFromJByteArray o(env, oid);
|
||||
object_ids.push_back(*o.PID);
|
||||
env->DeleteLocalRef(oid);
|
||||
jbyteArray object_id_bytes =
|
||||
static_cast<jbyteArray>(env->GetObjectArrayElement(objectIds, i));
|
||||
UniqueIdFromJByteArray object_id(env, object_id_bytes);
|
||||
object_ids.push_back(*object_id.PID);
|
||||
env->DeleteLocalRef(object_id_bytes);
|
||||
}
|
||||
|
||||
auto client = reinterpret_cast<LocalSchedulerConnection *>(c);
|
||||
auto conn = reinterpret_cast<LocalSchedulerConnection *>(client);
|
||||
|
||||
// Invoke wait.
|
||||
std::pair<std::vector<ObjectID>, std::vector<ObjectID>> result =
|
||||
local_scheduler_wait(client, object_ids, num_returns, timeout_ms,
|
||||
static_cast<bool>(wait_local));
|
||||
local_scheduler_wait(conn, object_ids, numReturns, timeoutMillis,
|
||||
static_cast<bool>(isWaitLocal));
|
||||
|
||||
// Convert result to java object.
|
||||
jboolean putValue = true;
|
||||
jboolean put_value = true;
|
||||
jbooleanArray resultArray = env->NewBooleanArray(object_ids.size());
|
||||
for (uint i = 0; i < result.first.size(); ++i) {
|
||||
for (uint j = 0; j < object_ids.size(); ++j) {
|
||||
if (result.first[i] == object_ids[j]) {
|
||||
env->SetBooleanArrayRegion(resultArray, j, 1, &putValue);
|
||||
env->SetBooleanArrayRegion(resultArray, j, 1, &put_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
putValue = false;
|
||||
put_value = false;
|
||||
for (uint i = 0; i < result.second.size(); ++i) {
|
||||
for (uint j = 0; j < object_ids.size(); ++j) {
|
||||
if (result.second[i] == object_ids[j]) {
|
||||
env->SetBooleanArrayRegion(resultArray, j, 1, &putValue);
|
||||
env->SetBooleanArrayRegion(resultArray, j, 1, &put_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -300,18 +249,23 @@ Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1waitObject(
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: nativeGenerateTaskId
|
||||
* Signature: ([B[BI)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1generateTaskId(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeGenerateTaskId(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jbyteArray did,
|
||||
jbyteArray ptid,
|
||||
jbyteArray driverId,
|
||||
jbyteArray parentTaskId,
|
||||
jint parent_task_counter) {
|
||||
UniqueIdFromJByteArray o1(env, did);
|
||||
ray::DriverID driver_id = *o1.PID;
|
||||
UniqueIdFromJByteArray object_id1(env, driverId);
|
||||
ray::DriverID driver_id = *object_id1.PID;
|
||||
|
||||
UniqueIdFromJByteArray o2(env, ptid);
|
||||
ray::TaskID parent_task_id = *o2.PID;
|
||||
UniqueIdFromJByteArray object_id2(env, parentTaskId);
|
||||
ray::TaskID parent_task_id = *object_id2.PID;
|
||||
|
||||
ray::TaskID task_id =
|
||||
ray::GenerateTaskId(driver_id, parent_task_id, parent_task_counter);
|
||||
|
||||
@@ -9,85 +9,61 @@ extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _init
|
||||
* Signature: (Ljava/lang/String;[B[BZJ)J
|
||||
* Method: nativeInit
|
||||
* Signature: (Ljava/lang/String;[BZ[BZ)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1init(JNIEnv *,
|
||||
jclass,
|
||||
jstring,
|
||||
jbyteArray,
|
||||
jbyteArray,
|
||||
jboolean,
|
||||
jbyteArray,
|
||||
jlong,
|
||||
jboolean);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeInit(JNIEnv *,
|
||||
jclass,
|
||||
jstring,
|
||||
jbyteArray,
|
||||
jboolean,
|
||||
jbyteArray,
|
||||
jboolean);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _submitTask
|
||||
* Signature: (JLjava/nio/ByteBuffer;II)V
|
||||
* Method: nativeSubmitTask
|
||||
* Signature: (J[BLjava/nio/ByteBuffer;IIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1submitTask(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jbyteArray,
|
||||
jobject,
|
||||
jint,
|
||||
jint,
|
||||
jboolean);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeSubmitTask(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jbyteArray,
|
||||
jobject,
|
||||
jint,
|
||||
jint,
|
||||
jboolean);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _getTaskTodo
|
||||
* Signature: (J)[B
|
||||
* Method: nativeGetTask
|
||||
* Signature: (JZ)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1getTaskTodo(JNIEnv *,
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeGetTask(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jboolean);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _computePutId
|
||||
* Signature: (J[BI)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1computePutId(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jbyteArray,
|
||||
jint);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _destroy
|
||||
* Method: nativeDestroy
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1destroy(JNIEnv *,
|
||||
jclass,
|
||||
jlong);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeDestroy(JNIEnv *,
|
||||
jclass,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _task_done
|
||||
* Signature: (J)V
|
||||
* Method: nativeReconstructObjects
|
||||
* Signature: (J[[BZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1task_1done(JNIEnv *,
|
||||
jclass,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _reconstruct_objects
|
||||
* Signature: (J[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1reconstruct_1objects(
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeReconstructObjects(
|
||||
JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
@@ -96,51 +72,53 @@ Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1reconstruct_1objects(
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _notify_unblocked
|
||||
* Method: nativeNotifyUnblocked
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1notify_1unblocked(JNIEnv *,
|
||||
jclass,
|
||||
jlong);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeNotifyUnblocked(
|
||||
JNIEnv *,
|
||||
jclass,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _put_object
|
||||
* Method: nativePutObject
|
||||
* Signature: (J[B[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1put_1object(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jbyteArray,
|
||||
jbyteArray);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativePutObject(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jbyteArray,
|
||||
jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _waitObject
|
||||
* Method: nativeWaitObject
|
||||
* Signature: (J[[BIIZ)[Z
|
||||
*/
|
||||
JNIEXPORT jbooleanArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1waitObject(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jobjectArray,
|
||||
jint,
|
||||
jint,
|
||||
jboolean);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeWaitObject(JNIEnv *,
|
||||
jclass,
|
||||
jlong,
|
||||
jobjectArray,
|
||||
jint,
|
||||
jint,
|
||||
jboolean);
|
||||
|
||||
/*
|
||||
* Class: org_ray_spi_impl_DefaultLocalSchedulerClient
|
||||
* Method: _generateTaskId
|
||||
* Method: nativeGenerateTaskId
|
||||
* Signature: ([B[BI)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient__1generateTaskId(JNIEnv *,
|
||||
jclass,
|
||||
jbyteArray,
|
||||
jbyteArray,
|
||||
jint);
|
||||
Java_org_ray_spi_impl_DefaultLocalSchedulerClient_nativeGenerateTaskId(
|
||||
JNIEnv *,
|
||||
jclass,
|
||||
jbyteArray,
|
||||
jbyteArray,
|
||||
jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user