Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / bindings / java / jmsg_vm.cpp
index ed2126b..a9174ba 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to the Virtual Machines.                               */
 
-/* Copyright (c) 2012-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2012-2023. 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. */
@@ -10,7 +10,6 @@
 #include "jxbt_utilities.hpp"
 #include "simgrid/Exception.hpp"
 #include "simgrid/plugins/live_migration.h"
-#include "src/kernel/context/Context.hpp"
 #include "src/kernel/resource/VirtualMachineImpl.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
@@ -71,10 +70,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_create(JNIEnv* env, jobject jVm,
 {
   sg_host_t host = jhost_get_native(env, jHost);
 
-  const char* name = env->GetStringUTFChars(jname, nullptr);
+  jstring_wrapper name(env, jname);
   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);
   jVm = env->NewGlobalRef(jVm);
@@ -175,16 +173,14 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_VM_getVMByName(JNIEnv* env, jclas
     jxbt_throw_null(env, "No VM can have a null name");
     return nullptr;
   }
-  const char* name = env->GetStringUTFChars(jname, nullptr);
+  jstring_wrapper name(env, jname);
   /* get the VM by name   (VMs are just special hosts, unfortunately) */
   auto const* host = sg_host_by_name(name);
 
   if (not host) { /* invalid name */
     jxbt_throw_host_not_found(env, name);
-    env->ReleaseStringUTFChars(jname, name);
     return nullptr;
   }
-  env->ReleaseStringUTFChars(jname, name);
 
   return static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
 }