- JNIEnv* env = this->jenv_;
- env->DeleteGlobalRef(this->jprocess_);
- XBT_ATTRIB_UNUSED 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