X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/71b6a2765baf41eb658e9f4ed80843de82c7bcfd..af0640ca0c4912e2b7d495a7a13233a16b79c54f:/src/bindings/java/JavaContext.cpp diff --git a/src/bindings/java/JavaContext.cpp b/src/bindings/java/JavaContext.cpp index e1a1e4e923..8013b2cc2e 100644 --- a/src/bindings/java/JavaContext.cpp +++ b/src/bindings/java/JavaContext.cpp @@ -1,6 +1,6 @@ /* Context switching within the JVM. */ -/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2009-2022. 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. */ @@ -8,7 +8,7 @@ #include "JavaContext.hpp" #include "jxbt_utilities.hpp" #include "simgrid/Exception.hpp" -#include "src/simix/smx_private.hpp" +#include "src/kernel/actor/ActorImpl.hpp" #include #include @@ -21,12 +21,6 @@ namespace simgrid { namespace kernel { namespace context { -ContextFactory* java_factory() -{ - XBT_INFO("Using regular java threads."); - return new JavaContextFactory(); -} - JavaContextFactory::JavaContextFactory() : ContextFactory() { xbt_assert(xbt::binary_name == "java"); @@ -39,12 +33,12 @@ Context* JavaContextFactory::create_context(std::function&& code, actor: return this->new_context(std::move(code), actor); } -void JavaContextFactory::run_all() +void JavaContextFactory::run_all(std::vector const& actors) { - SerialThreadContext::run_all(); + SerialThreadContext::run_all(actors); } -JavaContext::JavaContext(std::function&& code, smx_actor_t actor) +JavaContext::JavaContext(std::function&& code, actor::ActorImpl* actor) : SerialThreadContext(std::move(code), actor, false /* not maestro */) { /* ThreadContext already does all we need */ @@ -61,21 +55,26 @@ void JavaContext::start_hook() this->jenv_ = env; } -void JavaContext::stop_hook() +void JavaContext::stop() { - JNIEnv* env = this->jenv_; - env->DeleteGlobalRef(this->jprocess_); - jint error = __java_vm->DetachCurrentThread(); - if (error != JNI_OK) { - /* This is probably a Java thread, ie an actor not created from the XML (and thus from the C++), - * but from Java with something like new Process().start(). - * - * We should not even try to detach such threads. Instead, we throw a Java exception that will raise up - * until run_jprocess(), IIUC. - */ - jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); - XBT_DEBUG("Cannot detach the current thread"); - } + this->get_actor()->cleanup_from_self(); + + /* Unregister the thread from the JVM */ + JNIEnv* env = this->jenv_; + env->DeleteGlobalRef(this->jprocess_); + jint error = __java_vm->DetachCurrentThread(); + if (error != JNI_OK) { + /* This is probably a Java thread, ie an actor not created from the XML (and thus from the C++), + * but from Java with something like new Process().start(). + * + * We should not even try to detach such threads. Instead, we throw a Java exception that will raise up + * until run_jprocess(), IIUC. + */ + jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); + XBT_DEBUG("Cannot detach the current thread"); + } + + simgrid::ForcefulKillException::do_throw(); // clean RAII variables with the dedicated exception } }}} // namespace simgrid::kernel::context