X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b52ca441291c14eacf8cb9badfdfcbc95a618be6..b9625f82f86db0674e911887addce45dca31b57f:/src/bindings/java/jmsg.cpp diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 3b06e2e57b..6b71078aed 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -1,5 +1,3 @@ -/* Java Wrappers to the MSG API. */ - /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -12,7 +10,6 @@ #include #include "simgrid/Exception.hpp" -#include "simgrid/msg.h" #include "simgrid/plugins/energy.h" #include "simgrid/plugins/file_system.h" #include "simgrid/plugins/live_migration.h" @@ -33,7 +30,6 @@ #include "JavaContext.hpp" - /* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */ #ifndef JNIEXPORT #define JNIEXPORT @@ -134,22 +130,19 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv* env, jclass, jobjec JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv* env, jclass) { /* Run everything */ - XBT_DEBUG("Ready to run MSG_MAIN"); - msg_error_t rv = MSG_main(); - XBT_DEBUG("Done running MSG_MAIN"); - jxbt_check_res("MSG_main()", rv, MSG_OK, - xbt_strdup("unexpected error : MSG_main() failed .. please report this bug ")); - - XBT_INFO("MSG_main finished; Terminating the simulation..."); + XBT_DEBUG("Ready to run"); + simgrid_run(); + XBT_DEBUG("Done running"); + XBT_INFO("Terminating the simulation..."); /* Cleanup java hosts */ - xbt_dynar_t hosts = MSG_hosts_as_dynar(); - for (unsigned long index = 0; index < xbt_dynar_length(hosts) - 1; index++) { - auto const* msg_host = xbt_dynar_get_as(hosts, index, msg_host_t); - jobject jhost = (jobject) msg_host->extension(JAVA_HOST_LEVEL); + sg_host_t* hosts = sg_host_list(); + size_t host_count = sg_host_count(); + for (size_t index = 0; index < host_count - 1; index++) { + jobject jhost = (jobject)hosts[index]->extension(JAVA_HOST_LEVEL); if (jhost) jhost_unref(env, jhost); } - xbt_dynar_free(&hosts); + xbt_free(hosts); /* Cleanup java storages */ for (auto const& elm : java_storage_map) @@ -166,14 +159,14 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv* env, j { const char *platformFile = env->GetStringUTFChars(jplatformFile, 0); - MSG_create_environment(platformFile); + simgrid_load_platform(platformFile); env->ReleaseStringUTFChars(jplatformFile, platformFile); } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv* env, jclass) { - msg_netzone_t as = sg_zone_get_root(); + sg_netzone_t as = sg_zone_get_root(); jobject jas = jnetzone_new_instance(env); if (not jas) { jxbt_throw_jni(env, "java As instantiation failed"); @@ -311,13 +304,13 @@ static void java_main(int argc, char* argv[]) xbt_assert((jprocess != nullptr), "Process allocation failed."); jprocess = env->NewGlobalRef(jprocess); //bind the process to the context - const_sg_actor_t process = sg_actor_self(); + const_sg_actor_t actor = sg_actor_self(); context->jprocess_ = jprocess; /* sets the PID and the PPID of the process */ - env->SetIntField(jprocess, jprocess_field_Process_pid, static_cast(MSG_process_get_PID(process))); - env->SetIntField(jprocess, jprocess_field_Process_ppid, static_cast(MSG_process_get_PPID(process))); - jprocess_bind(jprocess, process, env); + env->SetIntField(jprocess, jprocess_field_Process_pid, static_cast(actor->get_pid())); + env->SetIntField(jprocess, jprocess_field_Process_ppid, static_cast(actor->get_ppid())); + jprocess_bind(jprocess, actor, env); run_jprocess(env, context->jprocess_); } @@ -330,11 +323,12 @@ namespace context { void java_main_jprocess(jobject jprocess) { JNIEnv *env = get_current_thread_env(); - simgrid::kernel::context::JavaContext* context = - static_cast(simgrid::kernel::context::Context::self()); - context->jprocess_ = jprocess; - jprocess_bind(context->jprocess_, MSG_process_self(), env); + JavaContext* context = static_cast(Context::self()); + context->jprocess_ = jprocess; + jprocess_bind(context->jprocess_, sg_actor_self(), env); run_jprocess(env, context->jprocess_); } -}}} +} // namespace context +} // namespace kernel +} // namespace simgrid