/* Functions related to the Virtual Machines. */
-/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2012-2019. 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. */
#include "jmsg_vm.h"
#include "jmsg_host.h"
-#include "jxbt_utilities.h"
+#include "jxbt_utilities.hpp"
+#include "simgrid/Exception.hpp"
+#include "simgrid/plugins/live_migration.h"
+#include "src/kernel/context/Context.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
-#include "xbt/ex.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
-SG_BEGIN_DECL()
-
extern int JAVA_HOST_LEVEL;
static jfieldID jvm_field_bind;
MSG_vm_set_bound(vm, bound);
}
-JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_create(JNIEnv* env, jobject jvm, jobject jhost, jstring jname,
- jint jramsize, jint jmig_netspeed, jint jdp_intensity)
+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);
+ msg_host_t host = jhost_get_native(env, jHost);
const char* name = env->GetStringUTFChars(jname, 0);
- msg_vm_t vm = MSG_vm_create(host, name, static_cast<int>(jramsize), static_cast<int>(jmig_netspeed),
- static_cast<int>(jdp_intensity));
+ 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));
env->ReleaseStringUTFChars(jname, name);
- jvm_bind(env, jvm, vm);
- jvm = env->NewWeakGlobalRef(jvm);
+ jvm_bind(env, jVm, vm);
+ jVm = env->NewGlobalRef(jVm);
// We use the extension level of the host, even if that's somehow disturbing
- vm->extension_set(JAVA_HOST_LEVEL, (void*)jvm);
+ vm->extension_set(JAVA_HOST_LEVEL, (void*)jVm);
}
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_VM_all(JNIEnv* env, jclass cls_arg)
msg_host_t h;
xbt_dynar_foreach (hosts, it, h) {
simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(h);
- if (vm != nullptr && vm->getState() != SURF_VM_STATE_DESTROYED) {
+ 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);
}
int count = vms.size();
jclass cls = jxbt_get_class(env, "org/simgrid/msg/VM");
- if (!cls)
+ if (not cls)
return nullptr;
jobjectArray jtable = env->NewObjectArray((jsize)count, cls, nullptr);
- if (!jtable) {
+ if (not jtable) {
jxbt_throw_jni(env, "Hosts table allocation failed");
return nullptr;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm)
{
msg_vm_t vm = jvm_get_native(env,jvm);
- if (vm) {
+ if (vm)
MSG_vm_shutdown(vm);
- auto vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
- vmList->erase(
- std::remove_if(vmList->begin(), vmList->end(), [vm](simgrid::s4u::VirtualMachine* it) {
- return vm == it;
- }),
- vmList->end());
+}
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_destroy(JNIEnv* env, jobject jvm)
+{
+ msg_vm_t vm = jvm_get_native(env, jvm);
+ if (vm) {
+ MSG_vm_destroy(vm);
+ auto* vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
+ vmList->erase(std::remove(vmList->begin(), vmList->end(), vm), vmList->end());
}
}
{
msg_vm_t vm = jvm_get_native(env,jvm);
msg_host_t host = jhost_get_native(env, jhost);
- try {
- MSG_vm_migrate(vm,host);
- }
- catch(xbt_ex& e){
- XBT_VERB("CATCH EXCEPTION MIGRATION %s",e.what());
- jxbt_throw_host_failure(env, (char*)"during migration");
+ if (not simgrid::ForcefulKillException::try_n_catch([&vm, &host]() { MSG_vm_migrate(vm, host); })) {
+ XBT_VERB("Caught exception during migration");
+ jxbt_throw_host_failure(env, "during migration");
}
}
/* get the C string from the java string */
if (jname == nullptr) {
- jxbt_throw_null(env, bprintf("No VM can have a null name"));
+ jxbt_throw_null(env, "No VM can have a null name");
return nullptr;
}
const char* name = env->GetStringUTFChars(jname, 0);
/* get the VM by name (VMs are just special hosts, unfortunately) */
msg_host_t host = MSG_host_by_name(name);
- if (!host) { /* invalid name */
+ if (not host) { /* invalid name */
jxbt_throw_host_not_found(env, name);
env->ReleaseStringUTFChars(jname, name);
return nullptr;
return static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
}
-SG_END_DECL()