31 #if defined (HAVE_CONFIG_H)
35 #if defined (HAVE_WINDOWS_H)
49 #include "builtin-defun-decls.h"
69 #if defined (HAVE_JAVA)
73 #if defined (HAVE_JAVA)
77 #if defined (OCTAVE_USE_WINDOWS_API)
78 # define LIBJVM_FILE_NAME "jvm.dll"
79 #elif defined (__APPLE__)
80 # define LIBJVM_FILE_NAME "libjvm.dylib"
81 # define JAVA_HOME_CMD "/usr/libexec/java_home"
83 # define LIBJVM_FILE_NAME "libjvm.so"
86 #define TO_JOBJECT(obj) reinterpret_cast<jobject> (obj)
87 #define TO_JCLASS(obj) reinterpret_cast<jclass> (obj)
89 #define TO_JNIENV(env) reinterpret_cast<JNIEnv *> (env)
120 operator bool ()
const {
return (
m_jobj != 0); }
163 box (JNIEnv *jni_env,
void *jobj,
void *jcls_arg =
nullptr);
166 box_more (JNIEnv *jni_env,
void *jobj_arg,
void *jcls_arg =
nullptr);
178 JNIEXPORT jboolean JNICALL
182 JNIEXPORT
void JNICALL
185 JNIEXPORT
void JNICALL
188 JNIEXPORT
void JNICALL
191 JNIEXPORT jboolean JNICALL
198 static JavaVM *
jvm =
nullptr;
235 m_vm_args.version = JNI_VERSION_1_6;
236 m_vm_args.nOptions = 0;
237 m_vm_args.options =
nullptr;
238 m_vm_args.ignoreUnrecognized =
false;
252 void add (
const std::string& opt)
254 m_java_opts.push_back (opt);
261 if (! js.bad () && ! js.fail ())
265 while (! js.eof () && ! js.fail ())
267 std::getline (js, line);
269 if (line.find (
'-') == 0)
270 m_java_opts.push_back (line);
272 warning (
"invalid JVM option, skipping: %s", line.c_str ());
281 if (m_vm_args.options !=
nullptr)
283 for (
int i = 0; i < m_vm_args.nOptions; i++)
284 delete [] m_vm_args.options[i].optionString;
286 delete [] m_vm_args.options;
288 m_vm_args.options =
nullptr;
289 m_vm_args.nOptions = 0;
297 if (m_java_opts.size () > 0)
301 m_vm_args.nOptions = m_java_opts.size ();
302 m_vm_args.options =
new JavaVMOption [m_vm_args.nOptions];
304 for (
const auto& opt : m_java_opts)
308 m_vm_args.options[index++].optionString =
strsave (opt.c_str ());
311 m_java_opts.clear ();
346 static std::string java_dir;
348 if (java_dir.empty ())
350 java_dir = octave::sys::env::getenv (
"OCTAVE_JAVA_DIR");
352 if (java_dir.empty ())
377 std::string classpath;
381 if (! fs.bad () && ! fs.fail ())
385 while (! fs.eof () && ! fs.fail ())
387 std::getline (fs, line);
388 if (line.length () > 0 && line[0] !=
'#' && line[0] !=
'%')
391 classpath.append (octave::directory_path::path_sep_str ());
394 int last = line.find_last_not_of (
" \t\f\v\r\n");
427 std::string retval = java_dir;
430 if (! retval.empty ())
434 std::string jar_file = java_dir + sep +
"octave.jar";
436 octave::sys::file_stat jar_exists (jar_file);
449 std::string cwd = octave::sys::env::get_current_directory ();
450 std::string home_dir = octave::sys::env::get_home_directory ();
454 std::vector<std::string> cp_list = {
"javaclasspath.txt",
458 for (std::string filename : cp_list)
460 std::string cp_file = filename;
461 octave::sys::file_stat cp_exists;
465 cp_exists = octave::sys::file_stat (cp_file);
470 retval.append (classpath);
477 cp_file =
'~' + sep + filename;
479 cp_exists = octave::sys::file_stat (cp_file);
484 retval.append (classpath);
492 cp_file = java_dir + sep + filename;
493 cp_exists = octave::sys::file_stat (cp_file);
498 retval.append (classpath);
504 error (
"octave.jar does not exist: %s", jar_file.c_str ());
507 error (
"initial java dir is empty");
517 #if defined (OCTAVE_USE_WINDOWS_API)
518 const std::array<const std::string, 2> subdirs = {
"bin/client",
"bin/server"};
520 const std::array<const std::string, 8> subdirs =
522 "jre/lib/server",
"jre/lib",
"lib/client",
"lib/server",
523 "jre/lib/amd64/client",
"jre/lib/amd64/server",
524 "jre/lib/i386/client",
"jre/lib/i386/server"
528 for (std::size_t i = 0; i < subdirs.size (); i++)
530 std::string candidate = java_home_path +
"/" + subdirs[i]
532 if (octave::sys::file_stat (candidate))
538 #if defined (OCTAVE_USE_WINDOWS_API)
543 get_regkey_value (HKEY h_rootkey,
const std::string subkey,
548 get_jvm_lib_path_from_registry ()
551 std::string key, jversion, value;
554 key = R
"(software\javasoft\jdk)";
556 jversion = octave::sys::env::getenv ("JAVA_VERSION");
557 bool maybe_version_15_or_newer =
true;
560 if (jversion.empty ())
562 value =
"CurrentVersion";
563 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
566 if (retval != ERROR_SUCCESS)
569 maybe_version_15_or_newer =
false;
570 key = R
"(software\javasoft\jre)";
571 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
574 if (retval != ERROR_SUCCESS)
577 key = R
"(software\javasoft\java runtime environment)";
578 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key,
583 if (retval != ERROR_SUCCESS)
584 error (
"unable to find Java Runtime Environment: %s::%s",
585 key.c_str (), value.c_str ());
587 jversion = regval.
xstring_value (
"initialize_jvm: registry value "
588 R
"("%s" at "%s" must be a string)",
589 value.c_str (), key.c_str ());
592 std::string jvm_lib_path;
593 if (maybe_version_15_or_newer)
596 key = key +
'\\' + jversion;
598 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
601 if (retval != ERROR_SUCCESS)
602 error (
"unable to find Java Runtime Environment: %s::%s",
603 key.c_str (), value.c_str ());
606 = regval.
xstring_value (R
"(initialize_jvm: registry value "%s" at )"
607 R"("%s" must be a string)",
608 value.c_str (), key.c_str ())
609 + R"(\bin\server\jvm.dll)";
611 if (! jvm_lib_path.empty ())
617 key = R
"(software\javasoft\jre\)" + jversion;
618 value = "RuntimeLib";
619 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
622 if (retval != ERROR_SUCCESS)
625 key = R
"(software\javasoft\java runtime environment\)" + jversion;
626 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
630 if (retval != ERROR_SUCCESS)
631 error (
"unable to find Java Runtime Environment: %s::%s",
632 key.c_str (), value.c_str ());
635 = regval.
xstring_value (R
"(initialize_jvm: registry value "%s" at )"
636 R"("%s" must be a string)",
637 value.c_str (), key.c_str ());
639 if (jvm_lib_path.empty ())
640 error (
"unable to find Java Runtime Environment: %s::%s",
641 key.c_str (), value.c_str ());
680 const char *static_locale = setlocale (LC_ALL,
nullptr);
683 locale = std::string (static_locale);
685 octave::dynamic_library lib (
"");
686 std::string jvm_lib_path;
690 (lib.search (
"JNI_CreateJavaVM"));
692 (lib.search (
"JNI_GetCreatedJavaVMs"));
694 if (create_vm && get_vm)
695 jvm_lib_path =
"linked in or loaded libraries";
699 std::string java_home_env = octave::sys::env::getenv (
"JAVA_HOME");
700 if (! java_home_env.empty ())
706 if (jvm_lib_path.empty ())
710 # if defined (__APPLE__)
712 if (jvm_lib_path.empty ())
714 octave::sys::file_stat libexec_java_home_exists (JAVA_HOME_CMD);
715 if (libexec_java_home_exists)
720 std::string java_home_cmd = std::string (JAVA_HOME_CMD)
721 +
" --failfast --version 1.6+ 2>/dev/null";
723 octave::process_execution_result rslt
726 if (rslt.exit_status () == 0)
728 std::string output = rslt.stdout_output ();
729 std::string found_path = output.substr (0, output.length() - 1);
731 if (!jvm_lib_found.empty ())
732 jvm_lib_path = jvm_lib_found;
738 if (jvm_lib_path.empty ())
740 #if defined (OCTAVE_USE_WINDOWS_API)
741 jvm_lib_path = get_jvm_lib_path_from_registry ();
748 lib = octave::dynamic_library (jvm_lib_path);
751 error (
"unable to load Java Runtime Environment from %s",
752 jvm_lib_path.c_str ());
755 (lib.search (
"JNI_CreateJavaVM"));
757 (lib.search (
"JNI_GetCreatedJavaVMs"));
760 error (
"unable to find JNI_CreateJavaVM in %s", jvm_lib_path.c_str ());
763 error (
"unable to find JNI_GetCreatedJavaVMs in %s",
764 jvm_lib_path.c_str ());
770 if (get_vm (&
jvm, 1, &nVMs) == 0 && nVMs > 0)
774 switch (
jvm->GetEnv (
reinterpret_cast<void **
> (¤t_env),
779 JavaVMAttachArgs m_vm_args;
780 m_vm_args.version = JNI_VERSION_1_6;
781 m_vm_args.name =
const_cast<char *
> (
"octave");
782 m_vm_args.group =
nullptr;
783 if (
jvm->AttachCurrentThread (
reinterpret_cast<void **
> (¤t_env),
785 error (
"JVM internal error, unable to attach octave to existing JVM");
789 error (
"JVM internal error, the required JNI version is not supported");
802 octave::JVMArgs m_vm_args;
806 #if defined (HAVE_BROKEN_PTHREAD_STACKSIZE)
807 m_vm_args.add (
"-Djdk.lang.processReaperUseDefaultStackSize=true");
809 m_vm_args.add (
"-Xrs");
816 if (create_vm (&
jvm, ¤t_env, m_vm_args.to_args ()) != JNI_OK)
817 error (
"unable to start Java VM in %s", jvm_lib_path.c_str ());
822 setlocale (LC_ALL, locale.c_str ());
840 jvm->DetachCurrentThread ();
842 jvm->DestroyJavaVM ();
863 const char *cstr = jni_env->GetStringUTFChars (s,
nullptr);
865 jni_env->ReleaseStringUTFChars (s, cstr);
878 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/String"));
881 if (jni_env->IsInstanceOf (obj, cls))
883 reinterpret_cast<jstring
> (obj));
896 static inline JNIEnv *
899 JNIEnv *
env =
nullptr;
902 jvm->GetEnv (
reinterpret_cast<void **
> (&
env), JNI_VERSION_1_6);
912 #if defined (HAVE_JAVA)
918 jclass_ref cls (current_env, current_env->FindClass (
"java/lang/String"));
937 #if defined (HAVE_JAVA)
941 std::string cls_cpp = cls_name;
942 std::replace (cls_cpp.begin (), cls_cpp.end (),
'.',
'/');
946 jclass_ref cls (current_env, current_env->FindClass (cls_cpp.c_str ()));
947 if (current_env->ExceptionCheck ())
948 current_env->ExceptionClear ();
956 octave_unused_parameter (cls_name);
966 #if defined (HAVE_JAVA)
978 jni_env->ExceptionDescribe ();
980 jni_env->ExceptionClear ();
982 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex));
983 jmethodID mID = jni_env->GetMethodID (jcls,
"toString",
984 "()Ljava/lang/String;");
986 reinterpret_cast<jstring
> (jni_env->CallObjectMethod (ex,
990 error (
"[java] %s", msg.c_str ());
1001 static std::string class_loader;
1002 static jclass uiClass =
nullptr;
1004 jclass jcls = jni_env->FindClass (name);
1006 if (jcls ==
nullptr)
1008 jni_env->ExceptionClear ();
1012 if (class_loader.empty ())
1015 jni_env->FindClass (
"java/lang/System"));
1016 jmethodID mID = jni_env->GetStaticMethodID
1019 "(Ljava/lang/String;)Ljava/lang/String;");
1021 jni_env->NewStringUTF (
"octave.class.loader"));
1022 js =
reinterpret_cast<jstring
> (jni_env->CallStaticObjectMethod
1023 (syscls, mID, jstring (js)));
1025 std::replace (class_loader.begin (), class_loader.end (),
1030 jni_env->FindClass (class_loader.c_str ()));
1034 jni_env->ExceptionClear ();
1037 std::replace (class_loader.begin (), class_loader.end (),
1040 jni_env->FindClass (
"org/openide/util/Lookup"));
1041 jmethodID mID = jni_env->GetStaticMethodID
1042 (jcls2,
"getDefault",
"()Lorg/openide/util/Lookup;");
1044 jni_env->CallStaticObjectMethod (jcls2, mID));
1045 mID = jni_env->GetMethodID (jcls2,
"lookup",
1046 "(Ljava/lang/Class;)Ljava/lang/Object;");
1048 jni_env->FindClass (
"java/lang/ClassLoader"));
1050 jni_env->CallObjectMethod
1051 (lObj, mID, jclass (cLoaderCls)));
1052 mID = jni_env->GetMethodID (cLoaderCls,
"loadClass",
1053 "(Ljava/lang/String;)Ljava/lang/Class;");
1055 jni_env->NewStringUTF (class_loader.c_str ()));
1056 uicls =
reinterpret_cast<jclass
>
1057 (jni_env->CallObjectMethod (cLoader, mID, jstring (js)));
1061 uiClass =
reinterpret_cast<jclass
>
1062 (jni_env->NewGlobalRef (jclass (uicls)));
1067 jmethodID mID = jni_env->GetStaticMethodID
1068 (uiClass,
"findClass",
"(Ljava/lang/String;)Ljava/lang/Class;");
1069 jstring_ref js (jni_env, jni_env->NewStringUTF (name));
1070 jcls =
reinterpret_cast<jclass
>
1071 (jni_env->CallStaticObjectMethod (uiClass, mID, jstring (js)));
1082 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj));
1083 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls));
1084 jmethodID isArray_ID = jni_env->GetMethodID (ccls,
"isArray",
"()Z");
1085 jmethodID getComponentType_ID = jni_env->GetMethodID (ccls,
1087 "()Ljava/lang/Class;");
1093 while (jcls && jni_env->CallBooleanMethod (jcls, isArray_ID))
1095 int len = (jobj ? jni_env->GetArrayLength (jobj) : 0);
1096 if (idx >= dv.
ndims ())
1099 jcls =
reinterpret_cast<jclass
>
1100 (jni_env->CallObjectMethod (jcls, getComponentType_ID));
1102 ?
reinterpret_cast<jobjectArray
> (jni_env->GetObjectArrayElement (jobj,
1116 jclass_ref ocls (jni_env, jni_env->FindClass (
"[I"));
1117 jobjectArray retval = jni_env->NewObjectArray (idx.
length (), ocls,
nullptr);
1121 for (
int i = 0; i < idx.
length (); i++)
1126 jintArray_ref i_array (jni_env, jni_env->NewIntArray (v.length ()));
1127 jint *buf = jni_env->GetIntArrayElements (i_array,
nullptr);
1131 for (
int k = 0; k < v.length (); k++)
1135 jni_env->ReleaseIntArrayElements (i_array, buf, 0);
1136 jni_env->SetObjectArrayElement (retval, i, i_array);
1140 catch (octave::index_exception& ie)
1143 ie.set_pos_if_unset (idx.
length (), i + 1);
1160 "org/octave/ClassHelper"));
1161 jmethodID mID = jni_env
1162 ->GetStaticMethodID (helperClass,
"arraySubsref",
1163 "(Ljava/lang/Object;[[I)Ljava/lang/Object;");
1164 resObj = jni_env->CallStaticObjectMethod
1165 (helperClass, mID, jobj, jobject (java_idx));
1168 retval =
box (jni_env, resObj);
1178 set_array_elements (JNIEnv *jni_env, jobject jobj,
1188 if (
unbox (jni_env, rhs, rhsObj, rhsCls))
1192 "org/octave/ClassHelper"));
1193 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"arraySubsasgn",
1194 "(Ljava/lang/Object;[[ILjava/lang/Object;)" "Ljava/lang/Object;");
1195 resObj = jni_env->CallStaticObjectMethod
1196 (helperClass, mID, jobj, jobject (java_idx), jobject (rhsObj));
1200 retval =
box (jni_env, resObj);
1210 get_invoke_list (JNIEnv *jni_env,
void *jobj_arg)
1214 std::list<std::string> name_list;
1218 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj));
1219 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls));
1220 jmethodID getMethods_ID = jni_env->GetMethodID
1221 (ccls,
"getMethods",
"()[Ljava/lang/reflect/Method;");
1222 jmethodID getFields_ID = jni_env->GetMethodID
1223 (ccls,
"getFields",
"()[Ljava/lang/reflect/Field;");
1225 reinterpret_cast<jobjectArray
>
1226 (jni_env->CallObjectMethod (cls, getMethods_ID)));
1228 reinterpret_cast<jobjectArray
>
1229 (jni_env->CallObjectMethod (cls, getFields_ID)));
1230 int mLen = jni_env->GetArrayLength (mList);
1231 int fLen = jni_env->GetArrayLength (fList);
1233 jni_env->FindClass (
"java/lang/reflect/Method"));
1235 jni_env->FindClass (
"java/lang/reflect/Field"));
1236 jmethodID m_getName_ID = jni_env->GetMethodID (mCls,
"getName",
1237 "()Ljava/lang/String;");
1238 jmethodID f_getName_ID = jni_env->GetMethodID (fCls,
"getName",
1239 "()Ljava/lang/String;");
1241 for (
int i = 0; i < mLen; i++)
1243 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i));
1244 jstring_ref methName (jni_env,
reinterpret_cast<jstring
>
1245 (jni_env->CallObjectMethod (meth,
1250 for (
int i = 0; i < fLen; i++)
1253 jni_env->GetObjectArrayElement (fList, i));
1255 reinterpret_cast<jstring
>
1256 (jni_env->CallObjectMethod
1257 (field, f_getName_ID)));
1266 return v.sort (
true);
1270 convert_to_string (JNIEnv *jni_env, jobject m_java_object,
bool force,
1275 if (jni_env && m_java_object)
1277 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/String"));
1279 if (jni_env->IsInstanceOf (m_java_object, cls))
1284 cls = jni_env->FindClass (
"[Ljava/lang/String;");
1286 if (jni_env->IsInstanceOf (m_java_object, cls))
1288 jobjectArray array =
reinterpret_cast<jobjectArray
> (m_java_object);
1289 int len = jni_env->GetArrayLength (array);
1292 for (
int i = 0; i <
len; i++)
1295 reinterpret_cast<jstring
>
1296 (jni_env->GetObjectArrayElement (array, i)));
1308 cls = jni_env->FindClass (
"java/lang/Object");
1309 jmethodID mID = jni_env->GetMethodID (cls,
"toString",
1310 "()Ljava/lang/String;");
1312 reinterpret_cast<jstring
>
1313 (jni_env->CallObjectMethod (m_java_object,
1323 error (
"unable to convert Java object to string");
1331 #define TO_JAVA(obj) dynamic_cast<octave_java *> ((obj).internal_rep ())
1344 is_auto_convertible_number (JNIEnv *jni_env, jobject jobj)
1347 cls = jni_env->FindClass (
"java/lang/Double");
1348 if (jni_env->IsInstanceOf (jobj, cls))
1350 cls = jni_env->FindClass (
"java/lang/Float");
1351 if (jni_env->IsInstanceOf (jobj, cls))
1353 cls = jni_env->FindClass (
"java/lang/Byte");
1354 if (jni_env->IsInstanceOf (jobj, cls))
1356 cls = jni_env->FindClass (
"java/lang/Short");
1357 if (jni_env->IsInstanceOf (jobj, cls))
1359 cls = jni_env->FindClass (
"java/lang/Integer");
1360 if (jni_env->IsInstanceOf (jobj, cls))
1362 cls = jni_env->FindClass (
"java/lang/Long");
1363 if (jni_env->IsInstanceOf (jobj, cls))
1390 box (JNIEnv *jni_env,
void *jobj_arg,
void *jcls_arg)
1407 cls = jni_env->FindClass (
"java/lang/Number");
1408 if (jni_env->IsInstanceOf (jobj, cls)
1409 && is_auto_convertible_number (jni_env, jobj))
1411 jmethodID
m = jni_env->GetMethodID (cls,
"doubleValue",
"()D");
1412 retval = jni_env->CallDoubleMethod (jobj,
m);
1416 cls = jni_env->FindClass (
"java/lang/Boolean");
1417 if (jni_env->IsInstanceOf (jobj, cls))
1419 jmethodID
m = jni_env->GetMethodID (cls,
"booleanValue",
"()Z");
1420 retval = (jni_env->CallBooleanMethod (jobj,
m) ? true :
false);
1424 cls = jni_env->FindClass (
"java/lang/String");
1425 if (jni_env->IsInstanceOf (jobj, cls))
1431 cls = jni_env->FindClass (
"java/lang/Character");
1432 if (jni_env->IsInstanceOf (jobj, cls))
1434 jmethodID
m = jni_env->GetMethodID (cls,
"charValue",
"()C");
1435 retval = jni_env->CallCharMethod (jobj,
m);
1440 #define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID) \
1441 cls = jni_env->FindClass (JAVA_ID); \
1442 if (jni_env->IsInstanceOf (jobj, cls)) \
1444 const JAVA_TYPE ## Array jarr = reinterpret_cast<JAVA_TYPE ## Array> (jobj); \
1445 const jsize len = jni_env->GetArrayLength (jarr); \
1446 OCTAVE_ID ## NDArray d (dim_vector (len, 1)); \
1447 JAVA_TYPE *buffer = reinterpret_cast<JAVA_TYPE *> (d.fortran_vec ()); \
1448 jni_env->Get ## JAVA_TYPE_CAP ## ArrayRegion (jarr, 0, len, buffer); \
1462 #undef BOX_PRIMITIVE_ARRAY
1468 if (jni_env->IsInstanceOf (jobj, cls))
1470 jmethodID mID = jni_env->GetMethodID (cls,
"getDims",
"()[I");
1472 reinterpret_cast<jintArray
>
1473 (jni_env->CallObjectMethod (jobj, mID)));
1474 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv),
1477 dims.
resize (jni_env->GetArrayLength (jintArray (iv)));
1479 for (
int i = 0; i < dims.
ndims (); i++)
1480 dims(i) = iv_data[i];
1482 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
1483 mID = jni_env->GetMethodID (cls,
"getClassName",
1484 "()Ljava/lang/String;");
1486 reinterpret_cast<jstring
>
1487 (jni_env->CallObjectMethod (jobj, mID)));
1494 mID = jni_env->GetMethodID (cls,
"toDouble",
"()[D");
1496 reinterpret_cast<jdoubleArray
>
1497 (jni_env->CallObjectMethod (jobj,
1499 jni_env->GetDoubleArrayRegion (dv, 0,
m.numel (),
1504 else if (s ==
"byte")
1509 mID = jni_env->GetMethodID (cls,
"toByte",
"()[B");
1511 reinterpret_cast<jbyteArray
>
1512 (jni_env->CallObjectMethod (jobj,
1514 jni_env->GetByteArrayRegion (dv, 0,
m.numel (),
1515 reinterpret_cast<jbyte *
>
1516 (
m.fortran_vec ()));
1523 mID = jni_env->GetMethodID (cls,
"toByte",
"()[B");
1525 reinterpret_cast<jbyteArray
>
1526 (jni_env->CallObjectMethod (jobj,
1528 jni_env->GetByteArrayRegion (dv, 0,
m.numel (),
1529 reinterpret_cast<jbyte *
>
1530 (
m.fortran_vec ()));
1535 else if (s ==
"integer")
1540 mID = jni_env->GetMethodID (cls,
"toInt",
"()[I");
1542 reinterpret_cast<jintArray
>
1543 (jni_env->CallObjectMethod (jobj,
1545 jni_env->GetIntArrayRegion (dv, 0,
m.numel (),
1546 reinterpret_cast<jint *
>
1547 (
m.fortran_vec ()));
1554 mID = jni_env->GetMethodID (cls,
"toInt",
"()[I");
1556 reinterpret_cast<jintArray
>
1557 (jni_env->CallObjectMethod (jobj,
1559 jni_env->GetIntArrayRegion (dv, 0,
m.numel (),
1560 reinterpret_cast<jint *
>
1561 (
m.fortran_vec ()));
1570 if (jni_env->IsInstanceOf (jobj, cls))
1572 jmethodID mID = jni_env->GetMethodID (cls,
"getID",
"()I");
1573 int ID = jni_env->CallIntMethod (jobj, mID);
1577 retval = it->second;
1590 box_more (JNIEnv *jni_env,
void *jobj_arg,
void *jcls_arg)
1605 cls = jni_env->FindClass (
"[D");
1607 if (jni_env->IsInstanceOf (jobj, cls))
1609 jdoubleArray jarr =
reinterpret_cast<jdoubleArray
> (jobj);
1610 int len = jni_env->GetArrayLength (jarr);
1615 jni_env->GetDoubleArrayRegion (jarr, 0,
len,
1626 cls = jni_env->FindClass (
"[[D");
1628 if (jni_env->IsInstanceOf (jobj, cls))
1630 jobjectArray jarr =
reinterpret_cast<jobjectArray
> (jobj);
1631 int rows = jni_env->GetArrayLength (jarr);
1638 for (
int r = 0;
r < rows;
r++)
1641 reinterpret_cast<jdoubleArray
>
1642 (jni_env->GetObjectArrayElement
1647 cols = jni_env->GetArrayLength (row);
1648 m.resize (cols, rows);
1650 jni_env->GetDoubleArrayRegion
1651 (row, 0, cols,
m.fortran_vec () +
r * cols);
1653 retval =
m.transpose ();
1662 cls = jni_env->FindClass (
"[Ljava/lang/String;");
1664 if (jni_env->IsInstanceOf (jobj, cls))
1666 jobjectArray jarr =
reinterpret_cast<jobjectArray
> (jobj);
1667 int len = jni_env->GetArrayLength (jarr);
1670 for (
int i = 0; i <
len; i++)
1673 reinterpret_cast<jstring
>
1674 (jni_env->GetObjectArrayElement (jarr, i)));
1702 jcls = jni_env->GetObjectClass (jobj);
1708 jobj = jni_env->NewStringUTF (s.c_str ());
1709 jcls = jni_env->GetObjectClass (jobj);
1716 jclass_ref scls (jni_env, jni_env->FindClass (
"java/lang/String"));
1717 jobjectArray array = jni_env->NewObjectArray (
n, scls,
nullptr);
1722 (str_arr(i).c_str ()));
1723 jni_env->SetObjectArrayElement (array, i, jstr);
1727 jcls = jni_env->GetObjectClass (jobj);
1734 #define UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP) \
1737 const OCTAVE_T ## NDArray v = val.METHOD_T ## array_value (); \
1738 JAVA_T ## Array jarr = jni_env->New ## JAVA_T_CAP ## Array (v.numel ()); \
1739 const JAVA_T *jv = reinterpret_cast<const JAVA_T *> (v.data ()); \
1740 jni_env->Set ## JAVA_T_CAP ## ArrayRegion (jarr, 0, v.numel (), jv); \
1741 jobj = reinterpret_cast<jobject> (jarr); \
1742 jcls = jni_env->GetObjectClass (jobj); \
1772 #undef UNBOX_PRIMITIVE_ARRAY
1779 #define UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON) \
1782 const OCTAVE_T ov = val.METHOD_T ## _value (); \
1783 jclass_ref dcls (jni_env, jni_env->FindClass (JAVA_T)); \
1784 const jfieldID fid = jni_env->GetStaticFieldID (dcls, "TYPE", "Ljava/lang/Class;"); \
1785 const jmethodID mid = jni_env->GetMethodID (dcls, "<init>", JAVA_CON); \
1786 jcls = reinterpret_cast<jclass> (jni_env->GetStaticObjectField (dcls, fid)); \
1787 jobj = jni_env->NewObject (dcls, mid, ov); \
1814 #undef UNBOX_PRIMITIVE_SCALAR
1828 jdoubleArray dv = jni_env->NewDoubleArray (
m.numel ());
1829 jni_env->SetDoubleArrayRegion (dv, 0,
m.numel (),
m.fortran_vec ());
1831 jcls = jni_env->GetObjectClass (jobj);
1838 "org/octave/Matrix"));
1841 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv),
nullptr);
1843 for (
int i = 0; i < dims.
ndims (); i++)
1844 iv_data[i] = dims(i);
1846 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
1852 jni_env->SetDoubleArrayRegion (jdoubleArray (dv), 0,
m.numel (),
1854 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([D[I)V");
1855 jobj = jni_env->NewObject (jclass (mcls), mID, jdoubleArray (dv),
1857 jcls = jni_env->GetObjectClass (jobj);
1863 jni_env->SetByteArrayRegion (jbyteArray (bv), 0,
m.numel (),
1864 reinterpret_cast<jbyte *
>
1865 (
m.fortran_vec ()));
1866 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([B[I)V");
1867 jobj = jni_env->NewObject
1868 (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
1869 jcls = jni_env->GetObjectClass (jobj);
1875 jni_env->SetByteArrayRegion (jbyteArray (bv), 0,
m.numel (),
1876 reinterpret_cast<jbyte *
>
1877 (
m.fortran_vec ()));
1878 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([B[I)V");
1879 jobj = jni_env->NewObject
1880 (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
1881 jcls = jni_env->GetObjectClass (jobj);
1887 jni_env->SetIntArrayRegion (jintArray (v), 0,
m.numel (),
1888 reinterpret_cast<jint *
>
1889 (
m.fortran_vec ()));
1890 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([I[I)V");
1891 jobj = jni_env->NewObject
1892 (jclass (mcls), mID, jintArray (v), jintArray (iv));
1893 jcls = jni_env->GetObjectClass (jobj);
1897 error (
"cannot convert matrix of type '%s'",
1904 jmethodID mID = jni_env->GetMethodID (rcls,
"<init>",
"(I)V");
1907 jobj = jni_env->NewObject (rcls, mID, ID);
1921 jclass_ref ocls (jni_env, jni_env->FindClass (
"java/lang/Object"));
1922 jclass_ref ccls (jni_env, jni_env->FindClass (
"java/lang/Class"));
1925 jobjs = jni_env->NewObjectArray (args.
length (), ocls,
nullptr);
1928 jclss = jni_env->NewObjectArray (args.
length (), ccls,
nullptr);
1930 for (
int i = 0; i < args.
length (); i++)
1935 found =
unbox (jni_env, args(i), jobj, jcls);
1939 jni_env->SetObjectArrayElement (jobjs, i, jobj);
1940 jni_env->SetObjectArrayElement (jclss, i, jcls);
1954 get_current_thread_ID (JNIEnv *jni_env)
1959 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/Thread"));
1960 jmethodID mID = jni_env->GetStaticMethodID (cls,
"currentThread",
1961 "()Ljava/lang/Thread;");
1962 jobject_ref jthread (jni_env, jni_env->CallStaticObjectMethod (cls, mID));
1967 jclass_ref jth_cls (jni_env, jni_env->GetObjectClass (jthread));
1968 mID = jni_env->GetMethodID (jth_cls,
"getId",
"()J");
1969 long result = jni_env->CallLongMethod (jthread, mID);
1982 java_event_hook (
void)
1990 "org/octave/Octave"));
1991 jmethodID mID = current_env->GetStaticMethodID
1992 (cls,
"checkPendingAction",
"()V");
1993 current_env->CallStaticVoidMethod (cls, mID);
2009 initialize_java (
void)
2019 octave::command_editor::add_event_hook (java_event_hook);
2023 catch (
const std::string msg)
2025 error (
"%s", msg.c_str ());
2032 JNIEXPORT jboolean JNICALL
2034 jobjectArray argin, jobjectArray argout)
2038 int nargout =
env->GetArrayLength (argout);
2039 int nargin =
env->GetArrayLength (argin);
2043 for (
int i = 0; i < nargin; i++)
2044 varargin(i) =
box (
env,
env->GetObjectArrayElement (argin, i),
nullptr);
2050 return unbox (
env, varargout, out_objs, out_clss);
2053 JNIEXPORT
void JNICALL
2059 JNIEXPORT
void JNICALL
2068 int len =
env->GetArrayLength (args);
2071 for (
int i = 0; i <
len; i++)
2074 oct_args(i) =
box (
env, jobj,
nullptr);
2084 && val.
cell_value()(0).is_function_handle ())
2089 for (
int i=1; i<c.
numel (); i++)
2090 oct_args(
len+i-1) = c(i);
2095 error (
"trying to invoke non-invocable object");
2099 JNIEXPORT
void JNICALL
2106 interp.eval_string (s,
false, pstatus, 0);
2109 JNIEXPORT jboolean JNICALL
2122 #if ! defined (HAVE_JAVA)
2132 #if defined (HAVE_JAVA)
2138 octave_unused_parameter (jobj);
2139 octave_unused_parameter (jcls);
2153 #if defined (HAVE_JAVA)
2160 octave_unused_parameter (ti);
2168 #if defined (HAVE_JAVA)
2189 const std::list<octave_value_list>& idx,
int nargout)
2191 #if defined (HAVE_JAVA)
2201 if (type.length () > 1 && type[1] ==
'(')
2206 ovl(0) = (idx.front ())(0);
2207 auto it = idx.begin ();
2209 retval = octave::FjavaMethod (
ovl, 1);
2217 ovl(1) = (idx.front ())(0);
2218 retval = octave::F__java_get__ (
ovl, 1);
2229 error (
"subsref: Java object cannot be indexed with %c", type[0]);
2233 if (idx.size () > 1 && type.length () > 1)
2234 retval = retval(0).next_subsref (nargout, type, idx, skip);
2240 octave_unused_parameter (type);
2241 octave_unused_parameter (idx);
2242 octave_unused_parameter (nargout);
2254 const std::list<octave_value_list>& idx,
2257 #if defined (HAVE_JAVA)
2266 if (type.length () == 1)
2272 ovl(1) = (idx.front ())(0);
2274 octave::F__java_set__ (
ovl);
2279 else if (type.length () > 2 && type[1] ==
'(')
2281 std::list<octave_value_list> new_idx;
2282 auto it = idx.begin ();
2283 new_idx.push_back (*it++);
2284 new_idx.push_back (*it++);
2287 std::list<octave_value_list> next_idx (idx);
2288 next_idx.erase (next_idx.begin ());
2289 next_idx.erase (next_idx.begin ());
2290 u(0).subsasgn (type.substr (2), next_idx, rhs);
2295 else if (type[1] ==
'.')
2299 std::list<octave_value_list> next_idx (idx);
2300 next_idx.erase (next_idx.begin ());
2301 u(0).subsasgn (type.substr (1), next_idx, rhs);
2307 error (
"invalid indexing/assignment on Java object");
2322 error (
"Java object cannot be indexed with %c", type[0]);
2330 octave_unused_parameter (type);
2331 octave_unused_parameter (idx);
2332 octave_unused_parameter (rhs);
2345 #if defined (HAVE_JAVA)
2350 return get_invoke_list (current_env,
to_java ());
2367 #if defined (HAVE_JAVA)
2379 octave_unused_parameter (force);
2380 octave_unused_parameter (type);
2400 os <<
"<Java object: " << m_java_classname << '>
';
2403 // FIXME: Need routines to actually save/load java objects through Serialize.
2407 octave_java::save_ascii (std::ostream& /* os */)
2409 warning ("save: unable to save java objects, skipping");
2415 octave_java::load_ascii (std::istream& /* is */)
2417 // Silently skip over java object that was not saved
2422 octave_java::save_binary (std::ostream& /* os */, bool /* save_as_floats */)
2424 warning ("save: unable to save java objects, skipping");
2430 octave_java::load_binary (std::istream& /* is */, bool /* swap*/,
2431 octave::mach_info::float_format /* fmt */)
2433 // Silently skip over java object that was not saved
2438 octave_java::save_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */,
2439 bool /* save_as_floats */)
2441 warning ("save: unable to save java objects, skipping");
2447 octave_java::load_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */)
2449 // Silently skip object that was not saved
2454 octave_java::do_javaMethod (void *jni_env_arg, const std::string& name,
2455 const octave_value_list& args)
2457 #if defined (HAVE_JAVA)
2459 octave_value retval;
2461 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
2465 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
2466 if (unbox (jni_env, args, arg_objs, arg_types))
2468 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
2469 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeMethod",
2470 "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
2471 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
2472 jobjectArray_ref resObj (jni_env,
2473 reinterpret_cast<jobjectArray> (jni_env->CallStaticObjectMethod (helperClass, mID,
2474 to_java (), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types))));
2476 retval = box (jni_env, resObj);
2478 retval = check_exception (jni_env);
2481 octave_set_default_fpucw ();
2488 octave_unused_parameter (jni_env_arg);
2489 octave_unused_parameter (name);
2490 octave_unused_parameter (args);
2492 // This shouldn't happen because construction of
octave_java objects is
2504 #if defined (HAVE_JAVA)
2510 octave_unused_parameter (name);
2511 octave_unused_parameter (args);
2523 const std::string& class_name,
2524 const std::string& name,
2527 #if defined (HAVE_JAVA)
2531 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2536 if (
unbox (jni_env, args, arg_objs, arg_types))
2540 "org/octave/ClassHelper"));
2541 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2542 "invokeStaticMethod",
2543 "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
2545 jni_env->NewStringUTF (name.c_str ()));
2547 jni_env->NewStringUTF (
class_name.c_str ()));
2549 jni_env->CallStaticObjectMethod (helperClass,
2553 jobjectArray (arg_objs),
2554 jobjectArray (arg_types)));
2556 retval =
box (jni_env, resObj);
2568 octave_unused_parameter (jni_env_arg);
2570 octave_unused_parameter (name);
2571 octave_unused_parameter (args);
2583 const std::string& name,
2586 #if defined (HAVE_JAVA)
2593 octave_unused_parameter (name);
2594 octave_unused_parameter (args);
2608 #if defined (HAVE_JAVA)
2612 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2618 if (
unbox (jni_env, args, arg_objs, arg_types))
2622 "org/octave/ClassHelper"));
2623 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2624 "invokeConstructor",
2625 "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
2627 jni_env->NewStringUTF (name.c_str ()));
2629 jni_env->CallStaticObjectMethod (helperClass,
2632 jobjectArray (arg_objs),
2633 jobjectArray (arg_types)));
2648 octave_unused_parameter (jni_env_arg);
2649 octave_unused_parameter (name);
2650 octave_unused_parameter (args);
2664 #if defined (HAVE_JAVA)
2670 octave_unused_parameter (name);
2671 octave_unused_parameter (args);
2684 #if defined (HAVE_JAVA)
2688 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2694 "org/octave/ClassHelper"));
2695 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"getField",
2696 "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
2697 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
2699 jni_env->CallStaticObjectMethod (helperClass,
2705 retval =
box (jni_env, resObj);
2716 octave_unused_parameter (jni_env_arg);
2717 octave_unused_parameter (name);
2730 #if defined (HAVE_JAVA)
2736 octave_unused_parameter (name);
2748 const std::string& name)
2750 #if defined (HAVE_JAVA)
2754 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2760 "org/octave/ClassHelper"));
2761 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2763 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
2765 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
2767 jni_env->CallStaticObjectMethod (helperClass, mID,
2771 retval =
box (jni_env, resObj);
2782 octave_unused_parameter (jni_env_arg);
2784 octave_unused_parameter (name);
2796 const std::string& name)
2798 #if defined (HAVE_JAVA)
2805 octave_unused_parameter (name);
2819 #if defined (HAVE_JAVA)
2823 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2830 if (
unbox (jni_env, val, jobj, jcls))
2834 "org/octave/ClassHelper"));
2835 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"setField",
2836 "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
2837 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
2838 jni_env->CallStaticObjectMethod (helperClass, mID,
to_java (),
2839 jstring (fName), jobject (jobj));
2850 octave_unused_parameter (jni_env_arg);
2851 octave_unused_parameter (name);
2852 octave_unused_parameter (val);
2865 #if defined (HAVE_JAVA)
2871 octave_unused_parameter (name);
2872 octave_unused_parameter (val);
2886 #if defined (HAVE_JAVA)
2890 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2897 if (
unbox (jni_env, val, jobj, jcls))
2901 "org/octave/ClassHelper"));
2902 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2904 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
2906 jni_env->NewStringUTF (
class_name.c_str ()));
2907 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
2908 jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName),
2909 jstring (fName), jobject (jobj));
2920 octave_unused_parameter (jni_env_arg);
2922 octave_unused_parameter (name);
2923 octave_unused_parameter (val);
2935 const std::string& name,
2938 #if defined (HAVE_JAVA)
2945 octave_unused_parameter (name);
2946 octave_unused_parameter (val);
2959 #if defined (HAVE_JAVA)
2977 m_java_class = current_env->NewGlobalRef (jclass (ocls));
2984 jmethodID mID = current_env->GetMethodID (clsCls,
2986 "()Ljava/lang/String;");
2995 octave_unused_parameter (jobj_arg);
2996 octave_unused_parameter (jcls_arg);
3009 #if defined (HAVE_JAVA)
3040 DEFUN (__java_init__, , ,
3052 #if defined (HAVE_JAVA)
3069 DEFUN (__java_exit__, , ,
3077 #if defined (HAVE_JAVA)
3090 DEFUN (javaObject, args, ,
3110 #if defined (HAVE_JAVA)
3115 std::string classname = args(0).xstring_value (
"javaObject: CLASSNAME must be a string");
3122 for (
int i=1; i<args.
length (); i++)
3129 octave_unused_parameter (args);
3145 DEFUN (javaMethod, args, ,
3171 #if defined (HAVE_JAVA)
3176 std::string methodname = args(0).xstring_value (
"javaMethod: METHODNAME must be a string");
3185 for (
int i=2; i<args.
length (); i++)
3188 if (args(1).isjava ())
3191 retval = jobj->
do_javaMethod (current_env, methodname, tmp);
3193 else if (args(1).is_string ())
3195 std::string cls = args(1).string_value ();
3199 error (
"javaMethod: OBJ must be a Java object or a string");
3205 octave_unused_parameter (args);
3224 DEFUN (__java_get__, args, ,
3246 #if defined (HAVE_JAVA)
3251 std::string name = args(1).xstring_value (
"__java_get__: NAME must be a string");
3259 if (args(0).isjava ())
3264 else if (args(0).is_string ())
3266 std::string cls = args(0).string_value ();
3270 error (
"__java_get__: OBJ must be a Java object or a string");
3276 octave_unused_parameter (args);
3283 DEFUN (__java_set__, args, ,
3306 #if defined (HAVE_JAVA)
3311 std::string name = args(1).xstring_value (
"__java_set__: NAME must be a string");
3319 if (args(0).isjava ())
3322 retval = jobj->
do_java_set (current_env, name, args(2));
3324 else if (args(0).is_string ())
3326 std::string cls = args(0).string_value ();
3330 error (
"__java_set__: OBJ must be a Java object or a string");
3336 octave_unused_parameter (args);
3343 DEFUN (__java2mat__, args, ,
3349 #if defined (HAVE_JAVA)
3360 if (args(0).isjava ())
3366 retval =
ovl (args(0));
3372 octave_unused_parameter (args);
3379 DEFUN (java_matrix_autoconversion, args, nargout,
3395 #if defined (HAVE_JAVA)
3398 "java_matrix_autoconversion");
3402 octave_unused_parameter (args);
3403 octave_unused_parameter (nargout);
3410 DEFUN (java_unsigned_autoconversion, args, nargout,
3427 #if defined (HAVE_JAVA)
3430 "java_unsigned_autoconversion");
3434 octave_unused_parameter (args);
3435 octave_unused_parameter (nargout);
3442 DEFUN (debug_java, args, nargout,
3457 #if defined (HAVE_JAVA)
3463 octave_unused_parameter (args);
3464 octave_unused_parameter (nargout);
3475 DEFUN (isjava, args, ,
3485 return ovl (args(0).isjava ());
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
void read_java_opts(const std::string &filename)
std::list< std::string > m_java_opts
JavaVMInitArgs * to_args()
void add(const std::string &opt)
Vector representing the dimensions (size) of an Array.
void resize(int n, int fill_value=0)
bool isvector(void) const
octave_idx_type ndims(void) const
Number of dimensions.
java_local_ref(JNIEnv *env, T obj)
java_local_ref(JNIEnv *env)
octave::refcount< octave_idx_type > count
OCTINTERP_API void newline(std::ostream &os) const
static void register_type(void)
friend class octave_value
static const std::string t_name
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_value do_java_set(void *jni_env, const std::string &name, const octave_value &val)
std::string m_java_classname
void print(std::ostream &os, bool pr_as_read_syntax=false)
void * to_java(void) const
octave_value do_javaMethod(void *jni_env, const std::string &name, const octave_value_list &args)
octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_value do_java_get(void *jni_env, const std::string &name)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool is_instance_of(const std::string &) const
bool is_java_string(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
void init(void *jobj, void *jcls)
static octave_value do_javaObject(void *jni_env, const std::string &name, const octave_value_list &args)
std::string class_name(void) const
dim_vector dims(void) const
string_vector map_keys(void) const
octave_value_list & append(const octave_value &val)
octave_idx_type length(void) const
OCTINTERP_API octave_function * function_value(bool silent=false) const
int32NDArray int32_array_value(void) const
bool iscellstr(void) const
OCTINTERP_API std::string xstring_value(const char *fmt,...) const
bool is_uint16_type(void) const
bool is_bool_scalar(void) const
bool is_int8_type(void) const
octave_idx_type rows(void) const
octave_idx_type numel(void) const
bool is_string(void) const
bool is_double_type(void) const
Cell cell_value(void) const
bool is_function_handle(void) const
std::string class_name(void) const
bool is_uint32_type(void) const
octave_idx_type columns(void) const
int8NDArray int8_array_value(void) const
bool is_int64_type(void) const
uint8NDArray uint8_array_value(void) const
std::string string_value(bool force=false) const
bool is_matrix_type(void) const
bool is_int32_type(void) const
bool is_uint64_type(void) const
bool is_int16_type(void) const
bool is_range(void) const
NDArray array_value(bool frc_str_conv=false) const
bool is_real_matrix(void) const
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
bool is_real_scalar(void) const
bool is_undefined(void) const
OCTINTERP_API octave_idx_type length(void) const
Array< std::string > cellstr_value(void) const
bool is_uint8_type(void) const
Matrix matrix_value(bool frc_str_conv=false) const
bool islogical(void) const
dim_vector dims(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string fcn_file_dir(void)
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
#define panic_impossible()
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
std::string dir_sep_str(void)
std::string tilde_expand(const std::string &name)
void octave_set_default_fpucw(void)
octave::idx_vector idx_vector
interpreter & __get_interpreter__(void)
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Z
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
static char * strsave(const char *s)
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
process_execution_result run_command_and_return_output(const std::string &cmd_str)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
static octave_value get_array_elements(JNIEnv *jni_env, jobject jobj, const octave_value_list &idx)
static octave_value check_exception(JNIEnv *jni_env)
#define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID)
static long octave_thread_ID
The thread id of the currently executing thread or -1 if this is unknown.
static std::string read_classpath_txt(const std::string &filepath)
Return the classpath in the given file filepath as a string.
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_call(JNIEnv *, jclass, jstring, jobjectArray, jobjectArray)
bool Vjava_unsigned_autoconversion
static std::string get_jvm_lib_path_in_subdir(std::string java_home_path)
java_local_ref< jthrowable > jthrowable_ref
#define UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON)
static bool jvm_attached
Whether the current thread is attached to the jvm given by jvm.
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_needThreadedInvokation(JNIEnv *, jclass)
static jobject make_java_index(JNIEnv *jni_env, const octave_value_list &idx)
static int octave_java_refcount
static std::string initial_java_dir(void)
The java initialization directory is given by the environment variable OCTAVE_JAVA_DIR if defined; ot...
static dim_vector compute_array_dimensions(JNIEnv *jni_env, jobject obj)
static std::map< int, octave_value > listener_map
java_local_ref< jdoubleArray > jdoubleArray_ref
java_local_ref< jobjectArray > jobjectArray_ref
java_local_ref< jclass > jclass_ref
jint(JNICALL * JNI_CreateJavaVM_t)(JavaVM **pvm, JNIEnv **penv, void *args)
static octave::dynamic_library jvm_lib
Need to keep hold of the shared library handle until exit.
java_local_ref< jbyteArray > jbyteArray_ref
static std::map< int, octave_value > octave_ref_map
static void initialize_jvm(void)
Initialize the java virtual machine (jvm) and field jvm if necessary.
static jclass find_octave_class(JNIEnv *jni_env, const char *name)
JNIEXPORT void JNICALL Java_org_octave_Octave_doInvoke(JNIEnv *, jclass, jint, jobjectArray)
static bool unbox(JNIEnv *jni_env, const octave_value &val, jobject_ref &jobj, jclass_ref &jcls)
JNIEXPORT void JNICALL Java_org_octave_Octave_doEvalString(JNIEnv *, jclass, jstring)
java_local_ref< jobject > jobject_ref
bool Vjava_matrix_autoconversion
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr)
#define UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP)
JNIEXPORT void JNICALL Java_org_octave_OctaveReference_doFinalize(JNIEnv *, jclass, jint)
static JNIEnv * thread_jni_env(void)
}
java_local_ref< jstring > jstring_ref
static void terminate_jvm(void)
Terminate the current jvm, if there is any.
static std::string jstring_to_string(JNIEnv *jni_env, jstring s)
Converts a Java string object to std::string.
static JavaVM * jvm
The pointer to a java virtual machine either created in the current thread or attached this thread to...
java_local_ref< jintArray > jintArray_ref
static octave_value box_more(JNIEnv *jni_env, void *jobj_arg, void *jcls_arg=nullptr)
static std::string initial_class_path(void)
Return the initial classpath.
jint(JNICALL * JNI_GetCreatedJavaVMs_t)(JavaVM **pvm, jsize bufLen, jsize *nVMs)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)