Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
useless stuff: do not use MSG in java bindings when possible
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 30 Mar 2020 14:18:48 +0000 (16:18 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 30 Mar 2020 14:51:54 +0000 (16:51 +0200)
12 files changed:
include/simgrid/storage.h
src/bindings/java/jmsg.cpp
src/bindings/java/jmsg_as.cpp
src/bindings/java/jmsg_as.hpp
src/bindings/java/jmsg_file.cpp
src/bindings/java/jmsg_file.h
src/bindings/java/jmsg_host.cpp
src/bindings/java/jmsg_host.h
src/bindings/java/jmsg_storage.cpp
src/bindings/java/jmsg_storage.h
src/bindings/java/jmsg_vm.cpp
src/bindings/java/jmsg_vm.h

index 5d01d18..b43b533 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <simgrid/forward.h>
 #include <xbt/base.h>
+#include <xbt/dict.h>
+#include <xbt/dynar.h>
 
 /* C interface */
 SG_BEGIN_DECL
index 2f1d5d7..3b06e2e 100644 (file)
@@ -84,7 +84,7 @@ void jmsg_throw_status(JNIEnv *env, msg_error_t status) {
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv*, jclass)
 {
-  return (jdouble) MSG_get_clock();
+  return (jdouble)simgrid_get_clock();
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv* env, jclass, jobjectArray jargs)
@@ -173,7 +173,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv* env, j
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv* env, jclass)
 {
-  msg_netzone_t as = MSG_zone_get_root();
+  msg_netzone_t as = sg_zone_get_root();
   jobject jas      = jnetzone_new_instance(env);
   if (not jas) {
     jxbt_throw_jni(env, "java As instantiation failed");
@@ -238,7 +238,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_deployApplication(JNIEnv* env, j
   const char *deploymentFile = env->GetStringUTFChars(jdeploymentFile, 0);
 
   simgrid_register_default(java_main);
-  MSG_launch_application(deploymentFile);
+  simgrid_load_deployment(deploymentFile);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit() {
@@ -263,8 +263,8 @@ static void run_jprocess(JNIEnv *env, jobject jprocess)
   // wait for the process's start time
   jfieldID jprocess_field_Process_startTime = jxbt_get_sfield(env, "org/simgrid/msg/Process", "startTime", "D");
   jdouble startTime = env->GetDoubleField(jprocess, jprocess_field_Process_startTime);
-  if (startTime > MSG_get_clock())
-    MSG_process_sleep(startTime - MSG_get_clock());
+  if (startTime > simgrid_get_clock())
+    simgrid::s4u::this_actor::sleep_for(startTime - simgrid_get_clock());
 
   //Execution of the "run" method.
   jmethodID id = jxbt_get_smethod(env, "org/simgrid/msg/Process", "run", "()V");
@@ -304,14 +304,14 @@ static void java_main(int argc, char* argv[])
   for (int i = 1; i < argc; i++)
       env->SetObjectArrayElement(args,i - 1, env->NewStringUTF(argv[i]));
   //Retrieve the host for the process.
-  jstring jhostName = env->NewStringUTF(MSG_host_self()->get_cname());
+  jstring jhostName = env->NewStringUTF(simgrid::s4u::Host::current()->get_cname());
   jobject jhost = Java_org_simgrid_msg_Host_getByName(env, nullptr, jhostName);
   //creates the process
   jobject jprocess = env->NewObject(class_Process, constructor_Process, jhost, jname, args);
   xbt_assert((jprocess != nullptr), "Process allocation failed.");
   jprocess = env->NewGlobalRef(jprocess);
   //bind the process to the context
-  const_sg_actor_t process = MSG_process_self();
+  const_sg_actor_t process = sg_actor_self();
 
   context->jprocess_ = jprocess;
   /* sets the PID and the PPID of the process */
index d9fddbd..405df10 100644 (file)
@@ -104,7 +104,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobje
   }
   const char *name = env->GetStringUTFChars(static_cast<jstring>(jname), 0);
 
-  const char* property = MSG_zone_get_property_value(as, name);
+  const char* property = sg_zone_get_property_value(as, name);
   if (not property) {
     return nullptr;
   }
index e22789b..2c40176 100644 (file)
@@ -7,7 +7,7 @@
 
 #ifndef JMSG_AS_HPP
 #define JMSG_AS_HPP
-#include "simgrid/msg.h"
+#include "simgrid/zone.h"
 #include <jni.h>
 
 extern "C" {
index 633deef..449f605 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "jmsg_file.h"
 #include "jxbt_utilities.hpp"
+#include <xbt/asserts.h>
 
 void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t fd) {
   env->SetLongField(jfile, jfile_field_bind, reinterpret_cast<std::intptr_t>(fd));
@@ -24,30 +25,30 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jpath) {
   const char *path = env->GetStringUTFChars((jstring) jpath, 0);
-  msg_file_t file  = MSG_file_open(path, nullptr);
+  sg_file_t file   = sg_file_open(path, nullptr);
   jfile_bind(env, jfile, file);
 
   env->ReleaseStringUTFChars(static_cast<jstring>(jpath), path);
 }
 
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize) {
-  msg_file_t file = jfile_get_native(env, jfile);
-  return static_cast<jlong>(MSG_file_read(file, static_cast<sg_size_t>(jsize)));
+  sg_file_t file = jfile_get_native(env, jfile);
+  return static_cast<jlong>(sg_file_read(file, static_cast<sg_size_t>(jsize)));
 }
 
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jlong jsize) {
-  msg_file_t file = jfile_get_native(env, jfile);
-  return static_cast<jlong>(MSG_file_write(file, static_cast<sg_size_t>(jsize)));
+  sg_file_t file = jfile_get_native(env, jfile);
+  return static_cast<jlong>(sg_file_write(file, static_cast<sg_size_t>(jsize)));
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_File_seek(JNIEnv *env, jobject jfile, jlong offset, jlong origin) {
-  msg_file_t file = jfile_get_native(env, jfile);
-  MSG_file_seek(file, static_cast<sg_offset_t>(offset), static_cast<int>(origin));
+  sg_file_t file = jfile_get_native(env, jfile);
+  sg_file_seek(file, static_cast<sg_offset_t>(offset), static_cast<int>(origin));
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) {
   const_sg_file_t file = jfile_get_native(env, jfile);
 
-  MSG_file_close(file);
+  sg_file_close(file);
   jfile_bind(env, jfile, nullptr);
 }
index 63c4530..367b872 100644 (file)
@@ -8,7 +8,6 @@
 #ifndef MSG_JFILE_H
 #define MSG_JFILE_H
 
-#include "simgrid/msg.h"
 #include "simgrid/plugins/file_system.h"
 #include <jni.h>
 
index 646250e..eab7f1b 100644 (file)
@@ -62,7 +62,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv* env, jclas
   }
   const char *name = env->GetStringUTFChars(jname, 0);
   /* get the host by name       (the hosts are created during the grid resolution) */
-  msg_host_t host = MSG_host_by_name(name);
+  sg_host_t host = sg_host_by_name(name);
 
   if (not host) { /* invalid name */
     jxbt_throw_host_not_found(env, name);
@@ -103,7 +103,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv* env, jclas
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) {
   jobject jhost;
 
-  msg_host_t host = MSG_host_self();
+  sg_host_t host = sg_host_self();
 
   if (not host->extension(JAVA_HOST_LEVEL)) {
     /* the native host not yet associated with the java host instance */
@@ -137,21 +137,18 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost) {
-  msg_host_t host = jhost_get_native(env, jhost);
-  MSG_host_on(host);
+  sg_host_t host = jhost_get_native(env, jhost);
+  sg_host_turn_on(host);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) {
-  msg_host_t host = jhost_get_native(env, jhost);
-  if (not simgrid::ForcefulKillException::try_n_catch([host]() { MSG_host_off(host); }))
+  sg_host_t host = jhost_get_native(env, jhost);
+  if (not simgrid::ForcefulKillException::try_n_catch([host]() { sg_host_turn_off(host); }))
     jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Host turned off");
 }
 
 JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
-  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
-  int nb_host = xbt_dynar_length(hosts);
-  xbt_dynar_free(&hosts);
-  return (jint) nb_host;
+  return (jint)sg_host_count();
 }
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobject jhost) {
@@ -162,7 +159,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobje
     return -1;
   }
 
-  return (jdouble) MSG_host_get_speed(host);
+  return (jdouble)sg_host_speed(host);
 }
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) {
@@ -173,7 +170,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env,
     return -1;
   }
 
-  return (jdouble) MSG_host_get_core_number(host);
+  return (jdouble)sg_host_core_count(host);
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) {
@@ -185,7 +182,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, job
   }
   const char *name = env->GetStringUTFChars((jstring) jname, 0);
 
-  const char *property = MSG_host_get_property_value(host, name);
+  const char* property = sg_host_get_property_value(host, name);
   if (not property) {
     return nullptr;
   }
@@ -199,7 +196,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, job
 
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue) {
-  msg_host_t host = jhost_get_native(env, jhost);
+  sg_host_t host = jhost_get_native(env, jhost);
 
   if (not host) {
     jxbt_throw_notbound(env, "host", jhost);
@@ -209,7 +206,7 @@ Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname,
   const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0);
   const char* value      = xbt_strdup(value_java);
 
-  MSG_host_set_property_value(host, name, value);
+  sg_host_set_property_value(host, name, value);
 
   env->ReleaseStringUTFChars((jstring) jvalue, value_java);
   env->ReleaseStringUTFChars((jstring) jname, name);
@@ -224,7 +221,7 @@ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject
     return 0;
   }
 
-  return (jboolean) MSG_host_is_on(host);
+  return (jboolean)sg_host_is_on(host);
 }
 
 JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost)
@@ -240,7 +237,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn
 
   int index = 0;
   jobjectArray jtable;
-  std::unordered_map<std::string, msg_storage_t> mounted_storages = host->get_mounted_storages();
+  std::unordered_map<std::string, sg_storage_t> mounted_storages = host->get_mounted_storages();
   int count  = mounted_storages.size();
   jclass cls = env->FindClass("org/simgrid/msg/Storage");
 
@@ -292,13 +289,13 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getStorageContent(JNIEn
     jxbt_throw_notbound(env, "host", jhost);
     return 0;
   }
-  return (jobjectArray)MSG_host_get_storage_content(host);
+  return (jobjectArray)sg_host_get_storage_content(host);
 }
 
 JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg)
 {
-  xbt_dynar_t table =  MSG_hosts_as_dynar();
-  int count = xbt_dynar_length(table);
+  sg_host_t* table = sg_host_list();
+  int count        = sg_host_count();
 
   jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
   if (not cls)
@@ -312,17 +309,16 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas
   }
 
   for (int index = 0; index < count; index++) {
-    auto const* host = xbt_dynar_get_as(table, index, msg_host_t);
-    jobject jhost   = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
+    jobject jhost = static_cast<jobject>(table[index]->extension(JAVA_HOST_LEVEL));
 
     if (not jhost) {
-      jstring jname = env->NewStringUTF(host->get_cname());
+      jstring jname = env->NewStringUTF(table[index]->get_cname());
       jhost         = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
     }
 
     env->SetObjectArrayElement(jtable, index, jhost);
   }
-  xbt_dynar_free(&table);
+  xbt_free(table);
   return jtable;
 }
 
@@ -347,39 +343,39 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *e
     return 0;
   }
 
-  return MSG_host_get_consumed_energy(host);
+  return sg_host_get_consumed_energy(host);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setPstate(JNIEnv* env, jobject jhost, jint pstate)
 {
-  msg_host_t host = jhost_get_native(env, jhost);
-  MSG_host_set_pstate(host, pstate);
+  sg_host_t host = jhost_get_native(env, jhost);
+  sg_host_set_pstate(host, pstate);
 }
 JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstate(JNIEnv* env, jobject jhost)
 {
   const_sg_host_t host = jhost_get_native(env, jhost);
-  return MSG_host_get_pstate(host);
+  return sg_host_get_pstate(host);
 }
 JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jobject jhost)
 {
   const_sg_host_t host = jhost_get_native(env, jhost);
-  return MSG_host_get_nb_pstates(host);
+  return sg_host_get_nb_pstates(host);
 }
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost)
 {
   const_sg_host_t host = jhost_get_native(env, jhost);
-  return MSG_host_get_speed(host);
+  return sg_host_speed(host);
 }
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate)
 {
   const_sg_host_t host = jhost_get_native(env, jhost);
-  return MSG_host_get_power_peak_at(host, pstate);
+  return sg_host_get_pstate_speed(host, pstate);
 }
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv* env, jobject jhost)
 {
   const_sg_host_t host = jhost_get_native(env, jhost);
-  return MSG_host_get_load(host);
+  return sg_host_load(host);
 }
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad (JNIEnv *env, jobject jhost)
@@ -391,7 +387,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad (JNIEnv *env,
     return 0;
   }
 
-  return MSG_host_get_current_load(host);
+  return sg_host_get_current_load(host);
 }
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getComputedFlops (JNIEnv *env, jobject jhost)
@@ -403,7 +399,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getComputedFlops (JNIEnv *en
     return 0;
   }
 
-  return MSG_host_get_computed_flops(host);
+  return sg_host_get_computed_flops(host);
 }
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getAvgLoad (JNIEnv *env, jobject jhost)
@@ -415,5 +411,5 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getAvgLoad (JNIEnv *env, job
     return 0;
   }
 
-  return MSG_host_get_avg_load(host);
+  return sg_host_get_avg_load(host);
 }
index 03bb0b0..7c72bde 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef MSG_JHOST_H
 #define MSG_JHOST_H
 
-#include "simgrid/msg.h"
+#include "simgrid/host.h"
 #include "simgrid/plugins/file_system.h"
 #include <jni.h>
 
@@ -33,10 +33,10 @@ jobject jhost_ref(JNIEnv * env, jobject jhost);
 void jhost_unref(JNIEnv * env, jobject jhost);
 
 /** Binds a native instance to a java instance. */
-void jhost_bind(jobject jhost, msg_host_t host, JNIEnv * env);
+void jhost_bind(jobject jhost, sg_host_t host, JNIEnv* env);
 
 /** Extracts the native instance associated to a java instance. */
-msg_host_t jhost_get_native(JNIEnv * env, jobject jhost);
+sg_host_t jhost_get_native(JNIEnv* env, jobject jhost);
 
 /** Initialize the native world, called from the Java world at startup */
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls);
index 4132d49..b88ed1c 100644 (file)
@@ -5,8 +5,8 @@
 /* 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. */
 
-#include "simgrid/msg.h"
 #include "simgrid/plugins/file_system.h"
+#include "simgrid/storage.h"
 
 #include "include/xbt/signal.hpp"
 #include "jmsg.hpp"
@@ -39,7 +39,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Storage_nativeInit(JNIEnv *env, jcla
              "Native initialization of msg/Storage failed. Please report that bug");
 }
 
-void jstorage_bind(jobject jstorage, msg_storage_t storage, JNIEnv * env) {
+void jstorage_bind(jobject jstorage, sg_storage_t storage, JNIEnv* env)
+{
   env->SetLongField(jstorage, jstorage_field_Storage_bind, (jlong) (uintptr_t) (storage));
 }
 
@@ -52,7 +53,7 @@ void jstorage_unref(JNIEnv * env, jobject jstorage) {
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, jclass cls, jstring jname) {
-  msg_storage_t storage;
+  sg_storage_t storage;
   jobject jstorage = nullptr;
 
   /* get the C string from the java string */
@@ -61,7 +62,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j
     return nullptr;
   }
   const char *name = env->GetStringUTFChars(jname, 0);
-  storage = MSG_storage_get_by_name(name);
+  storage          = sg_storage_get_by_name(name);
 
   if (not storage) { /* invalid name */
     jxbt_throw_storage_not_found(env, name);
@@ -110,7 +111,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getSize(JNIEnv * env,jobjec
     return -1;
   }
 
-  return (jlong) MSG_storage_get_size(storage);
+  return (jlong)sg_storage_get_size(storage);
 }
 
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv * env,jobject jstorage) {
@@ -121,7 +122,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv * env,jo
     return -1;
   }
 
-  return (jlong) MSG_storage_get_free_size(storage);
+  return (jlong)sg_storage_get_size_free(storage);
 }
 
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jobject jstorage) {
@@ -132,7 +133,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jo
     return -1;
   }
 
-  return (jlong) MSG_storage_get_used_size(storage);
+  return (jlong)sg_storage_get_size_used(storage);
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env, jobject jstorage, jobject jname) {
@@ -144,7 +145,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env,
   }
   const char *name = env->GetStringUTFChars((jstring) jname, 0);
 
-  const char *property = MSG_storage_get_property_value(storage, name);
+  const char* property = sg_storage_get_property_value(storage, name);
   if (not property) {
     return nullptr;
   }
@@ -157,7 +158,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env,
 
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject jname, jobject jvalue) {
-  msg_storage_t storage = jstorage_get_native(env, jstorage);
+  sg_storage_t storage = jstorage_get_native(env, jstorage);
 
   if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
@@ -179,7 +180,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getHost(JNIEnv * env,jobj
     jxbt_throw_notbound(env, "storage", jstorage);
     return nullptr;
   }
-  const char *host_name = MSG_storage_get_host(storage);
+  const char* host_name = sg_storage_get_host(storage);
   if (not host_name) {
     return nullptr;
   }
@@ -194,9 +195,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jc
   jobjectArray jtable;
   jobject jstorage;
   jstring jname;
-  msg_storage_t storage;
+  sg_storage_t storage;
 
-  xbt_dynar_t table =  MSG_storages_as_dynar();
+  xbt_dynar_t table = sg_storages_as_dynar();
   int count = xbt_dynar_length(table);
 
   jclass cls = jxbt_get_class(env, "org/simgrid/msg/Storage");
@@ -213,11 +214,11 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jc
   }
 
   for (index = 0; index < count; index++) {
-    storage = xbt_dynar_get_as(table,index,msg_storage_t);
+    storage = xbt_dynar_get_as(table, index, sg_storage_t);
     if (java_storage_map.find(storage) != java_storage_map.end()) {
       jstorage = java_storage_map.at(storage);
     } else {
-      jname = env->NewStringUTF(MSG_storage_get_name(storage));
+      jname    = env->NewStringUTF(sg_storage_get_name(storage));
       jstorage = Java_org_simgrid_msg_Storage_getByName(env, cls_arg, jname);
     }
 
index 183e109..d5e8a6b 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef MSG_JSTORAGE_H
 #define MSG_JSTORAGE_H
 
-#include "simgrid/msg.h"
+#include "simgrid/storage.h"
 #include <jni.h>
 
 SG_BEGIN_DECL
@@ -17,10 +17,10 @@ SG_BEGIN_DECL
 jobject jstorage_new_instance(JNIEnv * env);
 
 /** Binds a native instance to a java instance. */
-void jstorage_bind(jobject jstorage, msg_storage_t storage, JNIEnv * env);
+void jstorage_bind(jobject jstorage, sg_storage_t storage, JNIEnv* env);
 
 /** Extracts the native instance associated to a java instance. */
-msg_storage_t jstorage_get_native(JNIEnv * env, jobject jstorage);
+sg_storage_t jstorage_get_native(JNIEnv* env, jobject jstorage);
 
 /** Initialize the native world, called from the Java world at startup */
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Storage_nativeInit(JNIEnv *env, jclass cls);
index 0e7b60b..8083992 100644 (file)
@@ -18,14 +18,14 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
 extern int JAVA_HOST_LEVEL;
 static jfieldID jvm_field_bind;
 
-void jvm_bind(JNIEnv *env, jobject jvm, msg_vm_t vm)
+void jvm_bind(JNIEnv* env, jobject jvm, sg_vm_t vm)
 {
   env->SetLongField(jvm, jvm_field_bind, (intptr_t)vm);
 }
 
-msg_vm_t jvm_get_native(JNIEnv *env, jobject jvm)
+sg_vm_t jvm_get_native(JNIEnv* env, jobject jvm)
 {
-  return (msg_vm_t)(intptr_t)env->GetLongField(jvm, jvm_field_bind);
+  return (sg_vm_t)(intptr_t)env->GetLongField(jvm, jvm_field_bind);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeInit(JNIEnv *env, jclass cls)
@@ -37,43 +37,43 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeInit(JNIEnv *env, jclass cl
 
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_VM_isCreated(JNIEnv* env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  return MSG_vm_is_created(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  return sg_vm_is_created(vm);
 }
 
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_VM_isRunning(JNIEnv* env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  return MSG_vm_is_running(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  return sg_vm_is_running(vm);
 }
 
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_VM_isMigrating(JNIEnv* env, jobject jvm)
 {
   const_sg_vm_t vm = jvm_get_native(env, jvm);
-  return MSG_vm_is_migrating(vm);
+  return sg_vm_is_migrating(vm);
 }
 
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_VM_isSuspended(JNIEnv* env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  return MSG_vm_is_suspended(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  return sg_vm_is_suspended(vm);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_setBound(JNIEnv *env, jobject jvm, jdouble bound)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  MSG_vm_set_bound(vm, bound);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  sg_vm_set_bound(vm, bound);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_create(JNIEnv* env, jobject jVm, jobject jHost, jstring jname,
                                                       jint coreAmount, jint jramsize, jint jmig_netspeed,
                                                       jint jdp_intensity)
 {
-  msg_host_t host = jhost_get_native(env, jHost);
+  sg_host_t host = jhost_get_native(env, jHost);
 
   const char* name = env->GetStringUTFChars(jname, 0);
-  msg_vm_t vm      = MSG_vm_create_migratable(host, name, static_cast<int>(coreAmount), static_cast<int>(jramsize),
-                                         static_cast<int>(jmig_netspeed), static_cast<int>(jdp_intensity));
+  sg_vm_t vm       = sg_vm_create_migratable(host, name, static_cast<int>(coreAmount), static_cast<int>(jramsize),
+                                       static_cast<int>(jmig_netspeed), static_cast<int>(jdp_intensity));
   env->ReleaseStringUTFChars(jname, name);
 
   jvm_bind(env, jVm, vm);
@@ -84,19 +84,18 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_create(JNIEnv* env, jobject jVm,
 
 JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_VM_all(JNIEnv* env, jclass cls_arg)
 {
-  xbt_dynar_t hosts = MSG_hosts_as_dynar();
+  sg_host_t* hosts  = sg_host_list();
+  size_t host_count = sg_host_count();
   std::vector<jobject> vms;
 
-  unsigned int it;
-  msg_host_t h;
-  xbt_dynar_foreach (hosts, it, h) {
-    simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(h);
+  for (size_t i = 0; i < host_count; i++) {
+    simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(hosts[i]);
     if (vm != nullptr && vm->get_state() != simgrid::s4u::VirtualMachine::state::DESTROYED) {
       jobject jvm = static_cast<jobject>(vm->extension(JAVA_HOST_LEVEL));
       vms.push_back(jvm);
     }
   }
-  xbt_dynar_free(&hosts);
+  xbt_free(hosts);
 
   vms.shrink_to_fit();
   int count = vms.size();
@@ -120,28 +119,28 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_VM_all(JNIEnv* env, jclass c
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeFinalize(JNIEnv *env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  MSG_vm_destroy(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  sg_vm_destroy(vm);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  MSG_vm_start(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  sg_vm_start(vm);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
   if (vm)
-    MSG_vm_shutdown(vm);
+    sg_vm_shutdown(vm);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_destroy(JNIEnv* env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env, jvm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
   if (vm) {
-    MSG_vm_destroy(vm);
+    sg_vm_destroy(vm);
     auto* vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
     vmList->erase(std::remove(vmList->begin(), vmList->end(), vm), vmList->end());
   }
@@ -149,9 +148,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_destroy(JNIEnv* env, jobject jvm)
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeMigration(JNIEnv* env, jobject jvm, jobject jhost)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  msg_host_t host = jhost_get_native(env, jhost);
-  if (not simgrid::ForcefulKillException::try_n_catch([&vm, &host]() { MSG_vm_migrate(vm, host); })) {
+  sg_vm_t vm     = jvm_get_native(env, jvm);
+  sg_host_t host = jhost_get_native(env, jhost);
+  if (not simgrid::ForcefulKillException::try_n_catch([&vm, &host]() { sg_vm_migrate(vm, host); })) {
     XBT_VERB("Caught exception during migration");
     jxbt_throw_host_failure(env, "during migration");
   }
@@ -159,14 +158,14 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeMigration(JNIEnv* env, jobj
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_suspend(JNIEnv *env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  MSG_vm_suspend(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  sg_vm_suspend(vm);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_resume(JNIEnv *env, jobject jvm)
 {
-  msg_vm_t vm = jvm_get_native(env,jvm);
-  MSG_vm_resume(vm);
+  sg_vm_t vm = jvm_get_native(env, jvm);
+  sg_vm_resume(vm);
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_VM_getVMByName(JNIEnv* env, jclass cls, jstring jname)
@@ -178,7 +177,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_VM_getVMByName(JNIEnv* env, jclas
   }
   const char* name = env->GetStringUTFChars(jname, 0);
   /* get the VM by name   (VMs are just special hosts, unfortunately) */
-  auto const* host = MSG_host_by_name(name);
+  auto const* host = sg_host_by_name(name);
 
   if (not host) { /* invalid name */
     jxbt_throw_host_not_found(env, name);
index b15cd89..c03d00f 100644 (file)
@@ -8,8 +8,9 @@
 #ifndef MSG_VM_H
 #define MSG_VM_H
 
+#include "simgrid/host.h"
+#include "simgrid/vm.h"
 #include <jni.h>
-#include "simgrid/msg.h"
 
 SG_BEGIN_DECL
 
@@ -22,8 +23,8 @@ SG_BEGIN_DECL
 #endif
 /* end of eclipse-mandated pimple */
 
-void jvm_bind(JNIEnv *env, jobject jvm, msg_vm_t vm);
-msg_vm_t jvm_get_native(JNIEnv *env, jobject jvm);
+void jvm_bind(JNIEnv* env, jobject jvm, sg_vm_t vm);
+sg_vm_t jvm_get_native(JNIEnv* env, jobject jvm);
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeInit(JNIEnv* env, jclass cls);