Java
- Ensure that an actor can kill itself with Process::exit()
+ - Kill the obscure NativeException. Nobody want to survive the issues
+ it denotes, so use JniException that is a RuntimeException (not to
+ be catched explicitely).
-- target_date=March 20 2017 -- Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
package app.centralizedmutex;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.NativeException;
class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException {
+ public static void main(String[] args) {
Msg.init(args);
String platf = args.length > 1 ? args[0] : "../platforms/small_platform.xml";
import java.io.File;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.NativeException;
class Main {
public static final int TASK_COMP_SIZE = 10000000;
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException {
+ public static void main(String[] args) {
/* initialize the MSG simulation. Must be done before anything else (even logging). */
Msg.init(args);
* under the terms of the license (GNU LGPL) which comes with this package. */
package app.pingpong;
-import org.simgrid.msg.Msg;
import org.simgrid.msg.HostNotFoundException;
-import org.simgrid.msg.NativeException;
+import org.simgrid.msg.Msg;
class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws HostNotFoundException, NativeException{
+ public static void main(String[] args) throws HostNotFoundException {
Msg.init(args);
if(args.length < 1) {
Msg.info("Usage : Main platform_file");
package app.pingpong;
import org.simgrid.msg.Task;
-import org.simgrid.msg.NativeException;
public class PingPongTask extends Task {
private double timeVal;
- public PingPongTask() throws NativeException {
+ public PingPongTask() {
this.timeVal = 0;
}
- public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException {
+ public PingPongTask(String name, double computeDuration, double messageSize) {
super(name,computeDuration,messageSize);
}
* under the terms of the license (GNU LGPL) which comes with this package. */
package app.pingpong;
+import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.Task;
-import org.simgrid.msg.Process;
import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
-import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
public class Receiver extends Process {
private static final double COMM_SIZE_BW = 100000000;
- public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
- super(hostname,name,args);
+ public Receiver(String hostname, String name, String[]args) throws HostNotFoundException {
+ super(hostname, name, args);
}
public void main(String[] args) throws MsgException {
* under the terms of the license (GNU LGPL) which comes with this package. */
package app.pingpong;
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
-import org.simgrid.msg.Process;
-import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
public class Sender extends Process {
private static final double COMM_SIZE_LAT = 1;
- public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
+ public Sender(String hostname, String name, String[] args) throws HostNotFoundException {
super(hostname,name,args);
}
import org.simgrid.msg.Host;
import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.Process;
class Main {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws HostNotFoundException, NativeException {
+ public static void main(String[] args) throws HostNotFoundException {
Msg.init(args);
String platform = "../platforms/small_platform.xml";
* under the terms of the license (GNU LGPL) which comes with this package. */
package app.tokenring;
+import org.simgrid.msg.Host;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.Task;
-import org.simgrid.msg.Process;
import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
-import org.simgrid.msg.Host;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
public class RelayRunner extends Process {
private static final int TASK_COMM_SIZE = 1000000; /* The token is 1MB long*/
- public RelayRunner(Host host, String name, String[]args) throws NativeException {
+ public RelayRunner(Host host, String name, String[]args) {
super(host,name,args);
}
* and has nothing to do at the end as with Task.isend() where it must do a Comm.wait().
*/
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException, HostNotFoundException {
+ public static void main(String[] args) throws HostNotFoundException {
Msg.init(args);
String platform = "../platforms/small_platform.xml";
* and has nothing to do at the end as with Task.isend() where it must do a Comm.wait().
*/
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException, HostNotFoundException {
+ public static void main(String[] args) throws HostNotFoundException {
Msg.init(args);
String platform = "../platforms/small_platform.xml";
* under the terms of the license (GNU LGPL) which comes with this package. */
package async.yield;
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
-import org.simgrid.msg.Task;
+import org.simgrid.msg.Msg;
import org.simgrid.msg.Process;
-import org.simgrid.msg.HostFailureException;
-import org.simgrid.msg.TimeoutException;
-import org.simgrid.msg.TransferFailureException;
public class Yielder extends Process {
public Yielder (Host host, String name, String[] args) {
import java.util.ArrayList;
import java.util.List;
-import org.simgrid.msg.*;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
import org.simgrid.msg.Process;
+import org.simgrid.msg.VM;
public class Test extends Process{
- Test(String hostname, String name) throws HostNotFoundException, NativeException {
+ Test(String hostname, String name) throws HostNotFoundException {
super(hostname, name);
}
package cloud.migration;
-import org.simgrid.msg.*;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
import org.simgrid.msg.Process;
+import org.simgrid.msg.VM;
// This test aims at validating that the migration process is robust in face of host turning off either on the SRC
// node or on the DST node.
protected Host host1 = null;
protected Host host2 = null;
- TestHostOnOff(String hostname, String name) throws HostNotFoundException, NativeException {
+ TestHostOnOff(String hostname, String name) throws HostNotFoundException {
super(hostname, name);
}
import org.simgrid.msg.HostNotFoundException;
public class EnergyConsumer extends Process {
- public EnergyConsumer(String hostname, String name) throws HostNotFoundException{
+ public EnergyConsumer(String hostname, String name) throws HostNotFoundException {
super(hostname,name);
}
}
/* Construct the platform */
Msg.createEnvironment(args[0]);
- /* Instanciate a process */
+ /* Instantiate a process */
new EnergyConsumer("MyHost1","energyConsumer").start();
/* Execute the simulation */
Msg.run();
package energy.pstate;
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
import org.simgrid.msg.HostNotFoundException;
-import org.simgrid.msg.NativeException;
+import org.simgrid.msg.Msg;
class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException, HostNotFoundException {
+ public static void main(String[] args) throws HostNotFoundException {
Msg.energyInit();
Msg.init(args);
import org.simgrid.msg.HostFailureException;
import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.Process;
import org.simgrid.msg.Task;
import org.simgrid.msg.TaskCancelledException;
}
}
- PstateRunner(Host host, String name, String[] args) throws NativeException {
+ PstateRunner(Host host, String name, String[] args) {
super(host, name, args);
}
package energy.vm;
-import org.simgrid.msg.Msg;
-import org.simgrid.msg.VM;
import org.simgrid.msg.Host;
-import org.simgrid.msg.Task;
-import org.simgrid.msg.Process;
import org.simgrid.msg.HostFailureException;
import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
import org.simgrid.msg.TaskCancelledException;
-import org.simgrid.msg.NativeException;
+import org.simgrid.msg.VM;
/* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */
public class EnergyVMRunner extends Process {
}
}
- EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException, NativeException {
+ EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException {
super(host, name, args);
}
package energy.vm;
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
import org.simgrid.msg.HostNotFoundException;
-import org.simgrid.msg.NativeException;
+import org.simgrid.msg.Msg;
class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException, HostNotFoundException {
+ public static void main(String[] args) throws HostNotFoundException {
Msg.energyInit();
Msg.init(args);
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
public class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException {
+ public static void main(String[] args) {
/* initialize the MSG simulation. Must be done before anything else (even logging). */
Msg.init(args);
Msg.createEnvironment(args[0]);
* under the terms of the license (GNU LGPL) which comes with this package. */
package process.migration;
+import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.Msg;
import org.simgrid.msg.Mutex;
import org.simgrid.msg.Process;
-import org.simgrid.msg.NativeException;
-import org.simgrid.msg.HostNotFoundException;
class Main {
protected static Mutex mutex;
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException {
+ public static void main(String[] args) {
Msg.init(args);
if(args.length < 1) {
Msg.info("Usage : Migration platform_file");
package process.startkilltime;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.NativeException;
public class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException {
+ public static void main(String[] args) {
Msg.init(args);
if(args.length < 2) {
Msg.info("Usage : StartKilltime platform_file deployment_file");
package task.priority;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.NativeException;
/* Demonstrates the use of Task.setPriority to change the computation priority of a task */
public class Main {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws NativeException {
+ public static void main(String[] args) {
Msg.init(args);
if(args.length < 2) {
Msg.info("Usage : Priority platform_file deployment_file");
package trace.pingpong;
import org.simgrid.msg.Msg;
-import org.simgrid.trace.Trace;
import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
+import org.simgrid.trace.Trace;
public class Main {
private Main() {
throw new IllegalAccessError("Utility class");
}
- public static void main(String[] args) throws MsgException, NativeException {
+ public static void main(String[] args) throws MsgException {
Msg.init(args);
if(args.length < 1) {
Msg.info("Usage : Main platform_file");
* under the terms of the license (GNU LGPL) which comes with this package. */
package trace.pingpong;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.Task;
public class PingPongTask extends Task {
private double timeVal;
- public PingPongTask() throws NativeException {
+ public PingPongTask() {
this.timeVal = 0;
}
- public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException {
+ public PingPongTask(String name, double computeDuration, double messageSize) {
super(name,computeDuration,messageSize);
}
* under the terms of the license (GNU LGPL) which comes with this package. */
package trace.pingpong;
+import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
-import org.simgrid.msg.HostNotFoundException;
-import org.simgrid.msg.Task;
import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
import org.simgrid.trace.Trace;
public class Receiver extends Process {
private static final double COMM_SIZE_LAT = 1;
private static final double COMM_SIZE_BW = 100000000;
- public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException {
+ public Receiver(String hostname, String name, String[]args) throws HostNotFoundException {
super(hostname,name,args);
}
* under the terms of the license (GNU LGPL) which comes with this package. */
package trace.pingpong;
-import org.simgrid.msg.Msg;
import org.simgrid.msg.Host;
-import org.simgrid.msg.Task;
-import org.simgrid.msg.Process;
-import org.simgrid.msg.MsgException;
-import org.simgrid.msg.NativeException;
import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
import org.simgrid.trace.Trace;
public class Sender extends Process {
private static final double commSizeBw = 100000000;
private static final String PM_STATE = "PM_STATE";
- public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
+ public Sender(String hostname, String name, String[] args) throws HostNotFoundException {
super(hostname,name,args);
}
jxbt_throw_task_cancelled(env,nullptr);
break;
default:
- jxbt_throw_native(env,xbt_strdup("undefined message failed "
- "(please see jmsg_throw_status function in jmsg.cpp)"));
+ xbt_die("undefined message failed (please see jmsg_throw_status function in jmsg.cpp)");
}
}
return (simgrid::s4u::NetZone*)(uintptr_t)env->GetLongField(jas, jas_field_As_bind);
}
-JNIEXPORT void JNICALL Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls) {
+JNIEXPORT void JNICALL Java_org_simgrid_msg_As_nativeInit(JNIEnv* env, jclass cls)
+{
jclass class_As = env->FindClass("org/simgrid/msg/As");
jas_method_As_constructor = env->GetMethodID(class_As, "<init>", "()V");
jas_field_As_bind = jxbt_get_jfield(env,class_As, "bind", "J");
- if (!class_As || !jas_method_As_constructor || !jas_field_As_bind) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
- }
+ xbt_assert(class_As && jas_method_As_constructor && jas_field_As_bind,
+ "Native initialization of msg/AS failed. Please report that bug");
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) {
JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) {
jclass jfield_class_Comm = env->FindClass("org/simgrid/msg/Comm");
- if (!jfield_class_Comm) {
- jxbt_throw_native(env,bprintf("Can't find the org/simgrid/msg/Comm class."));
- return;
- }
+ xbt_assert(jfield_class_Comm, "Native initialization of msg/Comm failed. Please report that bug");
+
jcomm_field_Comm_bind = jxbt_get_jfield(env, jfield_class_Comm, "bind", "J");
jcomm_field_Comm_taskBind = jxbt_get_jfield(env, jfield_class_Comm, "taskBind", "J");
jcomm_field_Comm_receiving = jxbt_get_jfield(env, jfield_class_Comm, "receiving", "Z");
jtask_field_Comm_task = jxbt_get_jfield(env, jfield_class_Comm, "task", "Lorg/simgrid/msg/Task;");
jcomm_field_Comm_finished = jxbt_get_jfield(env, jfield_class_Comm, "finished", "Z");
- if (!jcomm_field_Comm_bind || !jcomm_field_Comm_taskBind || !jcomm_field_Comm_receiving || !jtask_field_Comm_task ||
- !jcomm_field_Comm_finished) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class."));
- }
+ xbt_assert(jcomm_field_Comm_bind && jcomm_field_Comm_taskBind && jcomm_field_Comm_receiving &&
+ jtask_field_Comm_task && jcomm_field_Comm_finished,
+ "Native initialization of msg/Comm failed. Please report that bug");
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm) {
}
if (!comm) {
- jxbt_throw_native(env,bprintf("comm is null"));
+ jxbt_throw_null(env, bprintf("comm is null"));
return JNI_FALSE;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble timeout) {
msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
if (!comm) {
- jxbt_throw_native(env,bprintf("comm is null"));
+ jxbt_throw_null(env, bprintf("comm is null"));
return;
}
comms[i] = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
if (!comms[i]) {
- jxbt_throw_native(env,bprintf("comm at rank %d is null",i));
+ jxbt_throw_null(env, bprintf("comm at rank %d is null", i));
return nullptr;
}
jhost_method_Host_constructor = env->GetMethodID(class_Host, "<init>", "()V");
jhost_field_Host_bind = jxbt_get_jfield(env,class_Host, "bind", "J");
jhost_field_Host_name = jxbt_get_jfield(env, class_Host, "name", "Ljava/lang/String;");
- if (!class_Host || !jhost_field_Host_name || !jhost_method_Host_constructor || !jhost_field_Host_bind) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
- }
+ xbt_assert(class_Host && jhost_field_Host_name && jhost_method_Host_constructor && jhost_field_Host_bind,
+ "Native initialization of msg/Host failed. Please report that bug");
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, jstring jname) {
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) {
jclass jprocess_class_Process = env->FindClass("org/simgrid/msg/Process");
+ xbt_assert(jprocess_class_Process, "Native initialization of msg/Process failed. Please report that bug");
jprocess_field_Process_name = jxbt_get_jfield(env, jprocess_class_Process, "name", "Ljava/lang/String;");
jprocess_field_Process_bind = jxbt_get_jfield(env, jprocess_class_Process, "bind", "J");
jprocess_field_Process_ppid = jxbt_get_jfield(env, jprocess_class_Process, "ppid", "I");
jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;");
jprocess_field_Process_killTime = jxbt_get_jfield(env, jprocess_class_Process, "killTime", "D");
- if (!jprocess_class_Process || !jprocess_field_Process_id || !jprocess_field_Process_name ||
- !jprocess_field_Process_pid || !jprocess_field_Process_ppid || !jprocess_field_Process_host) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
- }
+ xbt_assert(jprocess_field_Process_id && jprocess_field_Process_name && jprocess_field_Process_pid &&
+ jprocess_field_Process_ppid && jprocess_field_Process_host,
+ "Native initialization of msg/Process failed. Please report that bug");
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject jprocess_arg, jobject jhostname)
JNIEXPORT void JNICALL Java_org_simgrid_msg_Storage_nativeInit(JNIEnv *env, jclass cls) {
jclass class_Storage = env->FindClass("org/simgrid/msg/Storage");
+ xbt_assert(class_Storage, "Native initialization of msg/Storage failed. Please report that bug");
jstorage_method_Storage_constructor = env->GetMethodID(class_Storage, "<init>", "()V");
jstorage_field_Storage_bind = jxbt_get_jfield(env,class_Storage, "bind", "J");
jstorage_field_Storage_name = jxbt_get_jfield(env, class_Storage, "name", "Ljava/lang/String;");
- if (!class_Storage || !jstorage_field_Storage_name || !jstorage_method_Storage_constructor || !jstorage_field_Storage_bind) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
- }
+ xbt_assert(jstorage_field_Storage_name && jstorage_method_Storage_constructor && jstorage_field_Storage_bind,
+ "Native initialization of msg/Storage failed. Please report that bug");
}
void jstorage_bind(jobject jstorage, msg_storage_t storage, JNIEnv * env) {
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-static jfieldID jsyncro_field_Mutex_bind;
+static jfieldID jsynchro_field_Mutex_bind;
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_nativeInit(JNIEnv *env, jclass cls) {
- jsyncro_field_Mutex_bind = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
- if (!jsyncro_field_Mutex_bind) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
- }
+ jsynchro_field_Mutex_bind = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
+ xbt_assert(jsynchro_field_Mutex_bind, "Native initialization of msg/Mutex failed. Please report that bug");
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_init(JNIEnv * env, jobject obj) {
xbt_mutex_t mutex = xbt_mutex_init();
- env->SetLongField(obj, jsyncro_field_Mutex_bind, (jlong) (uintptr_t) (mutex));
+ env->SetLongField(obj, jsynchro_field_Mutex_bind, (jlong)(uintptr_t)(mutex));
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_acquire(JNIEnv * env, jobject obj) {
- xbt_mutex_t mutex = (xbt_mutex_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Mutex_bind);
+ xbt_mutex_t mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
try {
xbt_mutex_acquire(mutex);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj) {
xbt_mutex_t mutex;
- mutex = (xbt_mutex_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Mutex_bind);
+ mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
xbt_mutex_release(mutex);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_nativeFinalize(JNIEnv * env, jobject obj) {
- xbt_mutex_t mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsyncro_field_Mutex_bind);
+ xbt_mutex_t mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
xbt_mutex_destroy(mutex);
}
-static jfieldID jsyncro_field_Semaphore_bind;
+static jfieldID jsynchro_field_Semaphore_bind;
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_nativeInit(JNIEnv *env, jclass cls) {
- jsyncro_field_Semaphore_bind = jxbt_get_sfield(env, "org/simgrid/msg/Semaphore", "bind", "J");
- if (!jsyncro_field_Semaphore_bind) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Semaphore Java class. You should report this bug."));
- }
+ jsynchro_field_Semaphore_bind = jxbt_get_sfield(env, "org/simgrid/msg/Semaphore", "bind", "J");
+ xbt_assert(jsynchro_field_Semaphore_bind, "Native initialization of msg/Semaphore failed. Please report that bug");
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_init(JNIEnv * env, jobject obj, jint capacity) {
msg_sem_t sem = MSG_sem_init((int) capacity);
- env->SetLongField(obj, jsyncro_field_Semaphore_bind, (jlong) (uintptr_t) (sem));
+ env->SetLongField(obj, jsynchro_field_Semaphore_bind, (jlong)(uintptr_t)(sem));
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_acquire(JNIEnv * env, jobject obj, jdouble timeout) {
msg_sem_t sem;
- sem = (msg_sem_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Semaphore_bind);
+ sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
msg_error_t res = MSG_sem_acquire_timeout(sem, (double) timeout);
if (res != MSG_OK) {
jmsg_throw_status(env, res);
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_release(JNIEnv * env, jobject obj) {
msg_sem_t sem;
- sem = (msg_sem_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Semaphore_bind);
+ sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
MSG_sem_release(sem);
}
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Semaphore_wouldBlock(JNIEnv * env, jobject obj) {
msg_sem_t sem;
- sem = (msg_sem_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Semaphore_bind);
+ sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
int res = MSG_sem_would_block(sem);
return (jboolean) res;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_nativeFinalize(JNIEnv * env, jobject obj) {
msg_sem_t sem;
- sem = (msg_sem_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Semaphore_bind);
+ sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
MSG_sem_destroy(sem);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls) {
jclass jtask_class_Comm = env->FindClass("org/simgrid/msg/Comm");
jclass jtask_class_Task = env->FindClass("org/simgrid/msg/Task");
+ xbt_assert(jtask_class_Comm && jtask_class_Task,
+ "Native initialization of msg/Comm or msg/Task failed. Please report that bug");
jtask_method_Comm_constructor = env->GetMethodID(jtask_class_Comm, "<init>", "()V");
jtask_field_Task_bind = jxbt_get_jfield(env, jtask_class_Task, "bind", "J");
jtask_field_Comm_bind = jxbt_get_jfield(env, jtask_class_Comm, "bind", "J");
jtask_field_Comm_taskBind = jxbt_get_jfield(env, jtask_class_Comm, "taskBind", "J");
jtask_field_Comm_receiving = jxbt_get_jfield(env, jtask_class_Comm, "receiving", "Z");
- if (!jtask_field_Task_bind || !jtask_class_Task || !jtask_field_Comm_bind || !jtask_field_Comm_taskBind ||
- !jtask_field_Comm_receiving || !jtask_method_Comm_constructor) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class."));
- }
+ xbt_assert(jtask_field_Task_bind && jtask_field_Comm_bind && jtask_field_Comm_taskBind &&
+ jtask_field_Comm_receiving && jtask_method_Comm_constructor,
+ "Native initialization of msg/Task failed. Please report that bug");
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_create(JNIEnv * env, jobject jtask, jstring jname,
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox) {
- msg_comm_t comm;
- const char *mailbox;
- jclass comm_class;
+ jclass comm_class = env->FindClass("org/simgrid/msg/Comm");
+ if (!comm_class)
+ return nullptr;
+
//pointer to store the task object pointer.
msg_task_t *task = xbt_new(msg_task_t,1);
*task = nullptr;
/* There should be a cache here */
- comm_class = env->FindClass("org/simgrid/msg/Comm");
-
- if (!comm_class) {
- jxbt_throw_native(env,bprintf("fieldID or methodID or class not found."));
- return nullptr;
- }
jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
if (!jcomm) {
- jxbt_throw_native(env,bprintf("Can't create a Comm object."));
+ jxbt_throw_jni(env, "Can't create a Comm object.");
return nullptr;
}
- mailbox = env->GetStringUTFChars(jmailbox, 0);
-
- comm = MSG_task_irecv(task,mailbox);
+ const char* mailbox = env->GetStringUTFChars(jmailbox, 0);
+ msg_comm_t comm = MSG_task_irecv(task, mailbox);
+ env->ReleaseStringUTFChars(jmailbox, mailbox);
env->SetLongField(jcomm, jtask_field_Comm_bind, (jlong) (uintptr_t)(comm));
env->SetLongField(jcomm, jtask_field_Comm_taskBind, (jlong) (uintptr_t)(task));
env->SetBooleanField(jcomm, jtask_field_Comm_receiving, JNI_TRUE);
- env->ReleaseStringUTFChars(jmailbox, mailbox);
-
return jcomm;
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecvBounded(JNIEnv * env, jclass cls, jstring jmailbox,
jdouble rate)
{
- msg_comm_t comm;
- const char *mailbox;
- jclass comm_class;
- //pointer to store the task object pointer.
- msg_task_t *task = xbt_new(msg_task_t,1);
- *task = nullptr;
- /* There should be a cac hee */
- comm_class = env->FindClass("org/simgrid/msg/Comm");
-
- if (!comm_class) {
- jxbt_throw_native(env,bprintf("fieldID or methodID or class not found."));
+ jclass comm_class = env->FindClass("org/simgrid/msg/Comm");
+ if (!comm_class)
return nullptr;
- }
+
+ // pointer to store the task object pointer.
+ msg_task_t* task = xbt_new0(msg_task_t, 1);
jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
if (!jcomm) {
- jxbt_throw_native(env,bprintf("Can't create a Comm object."));
+ jxbt_throw_jni(env, "Can't create a Comm object.");
return nullptr;
}
- mailbox = env->GetStringUTFChars(jmailbox, 0);
-
- comm = MSG_task_irecv_bounded(task,mailbox, (double) rate);
+ const char* mailbox = env->GetStringUTFChars(jmailbox, 0);
+ msg_comm_t comm = MSG_task_irecv_bounded(task, mailbox, (double)rate);
+ env->ReleaseStringUTFChars(jmailbox, mailbox);
env->SetLongField(jcomm, jtask_field_Comm_bind, (jlong) (uintptr_t)(comm));
env->SetLongField(jcomm, jtask_field_Comm_taskBind, (jlong) (uintptr_t)(task));
env->SetBooleanField(jcomm, jtask_field_Comm_receiving, JNI_TRUE);
- env->ReleaseStringUTFChars(jmailbox, mailbox);
-
return jcomm;
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject jtask, jstring jmailbox)
{
- jclass comm_class;
- msg_task_t task;
- jobject jcomm;
msg_comm_t comm;
- const char *mailbox;
- comm_class = env->FindClass("org/simgrid/msg/Comm");
+ jclass comm_class = env->FindClass("org/simgrid/msg/Comm");
if (!comm_class) return nullptr;
- jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
- mailbox = env->GetStringUTFChars(jmailbox, 0);
+ jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
+ const char* mailbox = env->GetStringUTFChars(jmailbox, 0);
- task = jtask_to_native_task(jtask, env);
+ msg_task_t task = jtask_to_native_task(jtask, env);
if (!task) {
env->ReleaseStringUTFChars(jmailbox, mailbox);
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jobject jtask, jstring jmailbox,
jdouble maxrate)
{
- jclass comm_class;
msg_task_t task;
jobject jcomm;
msg_comm_t comm;
const char *mailbox;
- comm_class = env->FindClass("org/simgrid/msg/Comm");
-
- if (!comm_class) return nullptr;
+ jclass comm_class = env->FindClass("org/simgrid/msg/Comm");
+ if (!comm_class)
+ return nullptr;
jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
mailbox = env->GetStringUTFChars(jmailbox, 0);
{
jclass jprocess_class_VM = env->FindClass("org/simgrid/msg/VM");
jvm_field_bind = jxbt_get_jfield(env, jprocess_class_VM, "bind", "J");
- if (!jvm_field_bind ) {
- jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
- }
+ xbt_assert(jvm_field_bind, "Native initialization of msg/VM failed. Please report that bug");
}
JNIEXPORT jint JNICALL Java_org_simgrid_msg_VM_isCreated(JNIEnv * env, jobject jvm)
jxbt_throw_by_name(env, "org/simgrid/msg/JniException", bprintf("Internal error: %s %p not bound", kind, pointer));
}
-void jxbt_throw_native(JNIEnv * env, char *msg)
-{
- jxbt_throw_by_name(env, "org/simgrid/msg/NativeException", msg);
-}
-
void jxbt_throw_null(JNIEnv * env, char *msg)
{
jxbt_throw_by_name(env, "java/lang/NullPointerException", msg);
void jxbt_throw_jni(JNIEnv * env, const char *msg);
/** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer);
-/** Thrown on error in native MSG code */
-void jxbt_throw_native(JNIEnv * env, char *msg);
/** Thrown if NULL gets used */
void jxbt_throw_null(JNIEnv * env, char *msg);
+++ /dev/null
-/* This exception is raised when there is an error within the C world of SimGrid. */
-
-/* Copyright (c) 2006-2014. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-package org.simgrid.msg;
-
-/** Exception raised when there is an error within the C world of SimGrid. */
-public class NativeException extends MsgException {
- private static final long serialVersionUID = 1L;
-
- /** Constructs an <code>NativeException</code> with a detail message. */
- public NativeException(String s) {
- super(s);
- }
-}
* @param args The arguments of the main function of the process.
*
* @exception HostNotFoundException if no host with this name exists.
- * NativeException
- * @throws NativeException
*
*/
- public Process(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
+ public Process(String hostname, String name, String[] args) throws HostNotFoundException {
this(Host.getByName(hostname), name, args);
}
/**
public native boolean isSuspended();
/** Yield the current process. All other processes that are ready at the same timestamp will be executed first */
- public native static void yield();
+ public static native void yield();
/**
* Specify whether the process should restart when its host restarts after a failure
* @param PID The process identifier of the process to get.
*
* @return The process with the specified PID.
- *
- * @exception NativeException on error in the native SimGrid code
*/
- public static native Process fromPID(int PID) throws NativeException;
+ public static native Process fromPID(int PID);
/**
* This method returns the PID of the process.
*
*
* @return The storage object with the given name.
* @exception StorageNotFoundException if the name of the storage is not valid.
- * @exception NativeException if the native version of this method failed.
*/
public static native Storage getByName(String name)
- throws HostNotFoundException, NullPointerException, NativeException, StorageNotFoundException;
+ throws HostNotFoundException, NullPointerException, StorageNotFoundException;
/**
* This method returns the name of a storage.
* @throws HostFailureException
* @throws TransferFailureException
*/
- public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException, NativeException {
+ public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
send(mailbox, -1);
}
*
* @param mailbox where to send the message
* @param timeout
- * @exception NativeException if the retrieval fails.
* @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException
*/
- public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException, NativeException;
+ public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
/** Sends the task on the specified mailbox (capping the sending rate to \a maxrate)
*
src/bindings/java/org/simgrid/msg/Msg.java
src/bindings/java/org/simgrid/msg/MsgException.java
src/bindings/java/org/simgrid/msg/Mutex.java
- src/bindings/java/org/simgrid/msg/NativeException.java
src/bindings/java/org/simgrid/msg/Process.java
src/bindings/java/org/simgrid/msg/ProcessKilledError.java
src/bindings/java/org/simgrid/msg/ProcessNotFoundException.java