31 #if HAVE_FPU_CONTROL_H
32 #include <fpu_control.h>
37 #if defined (HAVE_WINDOWS_H)
60 typedef jint (JNICALL *JNI_CreateJavaVM_t) (JavaVM **pvm, JNIEnv **penv,
void *args);
61 typedef jint (JNICALL *JNI_GetCreatedJavaVMs_t) (JavaVM **pvm, jsize bufLen, jsize *nVMs);
65 JNIEXPORT jboolean JNICALL
66 Java_org_octave_Octave_call (JNIEnv *, jclass, jstring, jobjectArray,
68 JNIEXPORT
void JNICALL
69 Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint);
71 JNIEXPORT
void JNICALL
72 Java_org_octave_Octave_doInvoke (JNIEnv *, jclass, jint, jobjectArray);
74 JNIEXPORT
void JNICALL
75 Java_org_octave_Octave_doEvalString (JNIEnv *, jclass, jstring);
77 JNIEXPORT jboolean JNICALL
78 Java_org_octave_Octave_needThreadedInvokation (JNIEnv *, jclass);
81 static JavaVM *jvm = 0;
82 static bool jvm_attached =
false;
87 static std::map<int,octave_value> listener_map;
88 static std::map<int,octave_value> octave_ref_map;
89 static int octave_java_refcount = 0;
90 static long octave_thread_ID = -1;
102 vm_args.version = JNI_VERSION_1_2;
103 vm_args.nOptions = 0;
105 vm_args.ignoreUnrecognized =
false;
113 JavaVMInitArgs* to_args ()
119 void add (
const std::string& opt)
121 java_opts.push_back (opt);
124 void read_java_opts (
const std::string& filename)
126 std::ifstream js (filename.c_str ());
128 if (! js.bad () && ! js.fail ())
132 while (! js.eof () && ! js.fail ())
134 std::getline (js, line);
135 if (line.length () > 2
136 && (line.find (
"-D") == 0 || line.find (
"-X") == 0))
137 java_opts.push_back (line);
138 else if (line.length () > 0 && Vdebug_java)
139 std::cerr <<
"invalid JVM option, skipping: " << line << std::endl;
148 if (vm_args.options != 0)
150 for (
int i = 0; i < vm_args.nOptions; i++)
151 delete [] vm_args.options[i].optionString;
152 delete [] vm_args.options;
155 vm_args.nOptions = 0;
163 if (java_opts.size () > 0)
167 vm_args.nOptions = java_opts.size ();
168 vm_args.options =
new JavaVMOption [vm_args.nOptions];
169 for (std::list<std::string>::const_iterator it = java_opts.begin ();
170 it != java_opts.end (); ++it)
173 std::cout << *it << std::endl;
174 vm_args.options[index++].optionString =
strsave ((*it).c_str ());
182 JavaVMInitArgs vm_args;
184 std::list<std::string> java_opts;
189 read_registry_string (
const std::string& key,
const std::string& value)
196 if (! RegOpenKeyEx (HKEY_LOCAL_MACHINE, key.c_str (), 0, KEY_READ, &hkey))
198 if (! RegQueryValueEx (hkey, value.c_str (), 0, 0, 0, &len))
201 if (RegQueryValueEx (hkey, value.c_str (), 0, 0,
202 (LPBYTE)&retval[0], &len))
204 else if (retval[len-1] ==
'\0')
205 retval.resize (--len);
214 get_module_filename (HMODULE hMod)
217 std::string retval (n,
'\0');
222 int status = GetModuleFileName(hMod, &retval[0], n);
236 return (found ? retval :
"");
240 set_dll_directory (
const std::string& dir =
"")
242 typedef BOOL (WINAPI *dllfcn_t) (LPCTSTR path);
244 static dllfcn_t dllfcn = 0;
245 static bool first =
true;
247 if (! dllfcn && first)
249 HINSTANCE hKernel32 = GetModuleHandle (
"kernel32");
250 dllfcn =
reinterpret_cast<dllfcn_t
> (GetProcAddress (hKernel32,
251 "SetDllDirectoryA"));
256 dllfcn (dir.empty () ? 0 : dir.c_str ());
261 initial_java_dir (
void)
263 static std::string java_dir;
265 if (java_dir.empty ())
269 if (java_dir.empty ())
288 read_classpath_txt (
const std::string& filepath)
290 std::string classpath;
292 std::ifstream fs (filepath.c_str ());
294 if (! fs.bad () && ! fs.fail ())
298 while (! fs.eof () && ! fs.fail ())
300 std::getline (fs, line);
302 if (line.length () > 0)
304 if (line[0] ==
'#' || line[0] ==
'%')
312 int last = line.find_last_not_of (
" \t\f\v\r\n");
324 initial_class_path (
void)
326 std::string java_dir = initial_java_dir ();
328 std::string retval = java_dir;
331 if (! retval.empty ())
335 std::string jar_file = java_dir + sep +
"octave.jar";
352 std::string cp_list[] = {
"javaclasspath.txt",
"classpath.txt"};
354 for (
int i=0; i<2; i++)
356 std::string filename = cp_list[i];
357 std::string cp_file = filename;
366 std::string classpath = read_classpath_txt (cp_file);
367 retval.append (classpath);
372 cp_file =
"~" + sep + filename;
378 std::string classpath = read_classpath_txt (cp_file);
379 retval.append (classpath);
384 cp_file = java_dir + sep + filename;
389 std::string classpath = read_classpath_txt (cp_file);
390 retval.append (classpath);
395 throw std::string (
"octave.jar does not exist: ") + jar_file;
398 throw std::string (
"initial java dir is empty");
404 #if defined __i386__ || defined __x86_64__
405 #define _FPU_DEFAULT 0x037f
407 #define _FPU_DEFAULT 0
412 restore_fpu_state (
void)
414 fpucw_t cw = GET_FPUCW ();
415 if (cw != _FPU_DEFAULT)
416 SET_FPUCW (_FPU_DEFAULT);
420 initialize_jvm (
void)
427 const char *static_locale = setlocale (LC_ALL, 0);
428 const std::string locale (static_locale);
430 #if defined (__WIN32__)
432 HMODULE hMod = GetModuleHandle (
"jvm.dll");
433 std::string jvm_lib_path;
440 jvm_lib_path = get_module_filename (hMod);
442 if (jvm_lib_path.empty ())
443 throw std::string (
"unable to find Java Runtime Environment");
449 std::string key, value;
451 key =
"software\\javasoft\\java runtime environment";
456 value =
"Currentversion";
457 std::string regval = read_registry_string (key,value);
460 throw std::string (
"unable to find Java Runtime Environment: ") + key +
"::" + value;
464 key = key +
"\\" + value;
465 value =
"RuntimeLib";
466 jvm_lib_path = read_registry_string (key, value);
467 if (jvm_lib_path.empty ())
468 throw std::string (
"unable to find Java Runtime Environment: ") + key +
"::" + value;
470 std::string jvm_bin_path;
473 jvm_bin_path = read_registry_string (key, value);
474 if (! jvm_bin_path.empty ())
476 jvm_bin_path = (jvm_bin_path + std::string (
"\\bin"));
480 set_dll_directory (jvm_bin_path);
485 #else // Not Win32 system
488 #if defined (__APPLE__)
489 std::string jvm_lib_path = JAVA_LDPATH + std::string (
"/libjvm.dylib");
491 std::string jvm_lib_path = JAVA_LDPATH + std::string (
"/libjvm.so");
498 # if !defined (__APPLE__) && !defined (__MACH__)
503 throw std::string (
"unable to load Java Runtime Environment from ") + jvm_lib_path;
505 #if defined (__WIN32__)
507 set_dll_directory ();
509 if (! old_cwd.empty ())
514 JNI_CreateJavaVM_t create_vm =
515 reinterpret_cast<JNI_CreateJavaVM_t
> (lib.search (
"JNI_CreateJavaVM"));
516 JNI_GetCreatedJavaVMs_t get_vm =
517 reinterpret_cast<JNI_GetCreatedJavaVMs_t
> (lib.search (
"JNI_GetCreatedJavaVMs"));
520 throw std::string (
"unable to find JNI_CreateJavaVM in ") + jvm_lib_path;
523 throw std::string (
"unable to find JNI_GetCreatedJavaVMs in ") + jvm_lib_path;
525 if (get_vm (&jvm, 1, &nVMs) == 0 && nVMs > 0)
533 if (JNI_GetCreatedJavaVMs (&jvm, 1, &nVMs) == 0 && nVMs > 0)
540 switch (jvm->GetEnv (reinterpret_cast<void **> (¤t_env), JNI_VERSION_1_2))
544 JavaVMAttachArgs vm_args;
545 vm_args.version = JNI_VERSION_1_2;
546 vm_args.name =
const_cast<char *
> (
"octave");
548 if (jvm->AttachCurrentThread (reinterpret_cast<void **> (¤t_env),
550 throw std::string (
"JVM internal error, unable to attach octave to existing JVM");
554 throw std::string (
"JVM internal error, the required JNI version is not supported");
571 vm_args.add (
"-Djava.class.path=" + initial_class_path ());
572 vm_args.add (
"-Xrs");
573 vm_args.add (
"-Djava.system.class.loader=org.octave.OctClassLoader");
576 # if !defined (__APPLE__) && !defined (__MACH__)
578 if (create_vm (&jvm, ¤t_env, vm_args.to_args ()) != JNI_OK)
579 throw std::string (
"unable to start Java VM in ")+jvm_lib_path;
587 if (JNI_CreateJavaVM (&jvm, reinterpret_cast<void **> (¤t_env),
588 vm_args.to_args ()) != JNI_OK)
589 throw std::string (
"unable to start Java VM in ")+jvm_lib_path;
595 setlocale (LC_ALL, locale.c_str ());
604 jvm->DetachCurrentThread ();
606 jvm->DestroyJavaVM ();
609 jvm_attached =
false;
614 restore_fpu_state ();
625 const char *cstr = jni_env->GetStringUTFChars (s, 0);
627 jni_env->ReleaseStringUTFChars (s, cstr);
640 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/String"));
643 if (jni_env->IsInstanceOf (obj, cls))
645 reinterpret_cast<jstring> (obj));
659 jclass_ref cls (current_env, current_env->FindClass (
"java/lang/String"));
660 return current_env->IsInstanceOf (
java_object, cls);
667 check_exception (JNIEnv* jni_env)
676 jni_env->ExceptionDescribe ();
678 jni_env->ExceptionClear ();
680 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex));
681 jmethodID mID = jni_env->GetMethodID (jcls,
"toString",
682 "()Ljava/lang/String;");
684 reinterpret_cast<jstring> (jni_env->CallObjectMethod (ex, mID)));
687 error (
"[java] %s", msg.c_str ());
696 find_octave_class (JNIEnv *jni_env,
const char *name)
698 static std::string class_loader;
699 static jclass uiClass = 0;
701 jclass jcls = jni_env->FindClass (name);
705 jni_env->ExceptionClear ();
709 if (class_loader.empty ())
712 jni_env->FindClass (
"java/lang/System"));
713 jmethodID mID = jni_env->GetStaticMethodID (syscls,
"getProperty",
"(Ljava/lang/String;)Ljava/lang/String;");
714 jstring_ref js (jni_env, jni_env->NewStringUTF (
"octave.class.loader"));
715 js =
reinterpret_cast<jstring
> (jni_env->CallStaticObjectMethod (syscls, mID, jstring (js)));
717 std::replace (class_loader.begin (), class_loader.end (),
'.',
'/');
720 jclass_ref uicls (jni_env, jni_env->FindClass (class_loader.c_str ()));
724 jni_env->ExceptionClear ();
727 std::replace (class_loader.begin (), class_loader.end (),
'/',
'.');
728 jclass_ref jcls2 (jni_env, jni_env->FindClass (
"org/openide/util/Lookup"));
729 jmethodID mID = jni_env->GetStaticMethodID (jcls2,
"getDefault",
"()Lorg/openide/util/Lookup;");
730 jobject_ref lObj (jni_env, jni_env->CallStaticObjectMethod (jcls2, mID));
731 mID = jni_env->GetMethodID (jcls2,
"lookup",
"(Ljava/lang/Class;)Ljava/lang/Object;");
732 jclass_ref cLoaderCls (jni_env, jni_env->FindClass (
"java/lang/ClassLoader"));
733 jobject_ref cLoader (jni_env, jni_env->CallObjectMethod (lObj, mID, jclass (cLoaderCls)));
734 mID = jni_env->GetMethodID (cLoaderCls,
"loadClass",
"(Ljava/lang/String;)Ljava/lang/Class;");
735 jstring_ref js (jni_env, jni_env->NewStringUTF (class_loader.c_str ()));
736 uicls =
reinterpret_cast<jclass
> (jni_env->CallObjectMethod (cLoader, mID, jstring (js)));
740 uiClass =
reinterpret_cast<jclass
> (jni_env->NewGlobalRef (jclass (uicls)));
745 jmethodID mID = jni_env->GetStaticMethodID (uiClass,
"findClass",
"(Ljava/lang/String;)Ljava/lang/Class;");
746 jstring_ref js (jni_env, jni_env->NewStringUTF (name));
747 jcls =
reinterpret_cast<jclass
> (jni_env->CallStaticObjectMethod (uiClass, mID, jstring (js)));
755 compute_array_dimensions (JNIEnv* jni_env, jobject obj)
758 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj));
759 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls));
760 jmethodID isArray_ID = jni_env->GetMethodID (ccls,
"isArray",
"()Z");
761 jmethodID getComponentType_ID = jni_env->GetMethodID (ccls,
"getComponentType",
"()Ljava/lang/Class;");
767 while (jcls && jni_env->CallBooleanMethod (jcls, isArray_ID))
769 int len = (jobj ? jni_env->GetArrayLength (jobj) : 0);
770 if (idx >= dv.length ())
773 jcls =
reinterpret_cast<jclass
> (jni_env->CallObjectMethod (jcls, getComponentType_ID));
774 jobj = (len > 0 ?
reinterpret_cast<jobjectArray
> (jni_env->GetObjectArrayElement (jobj, 0)) : 0);
778 restore_fpu_state ();
786 jclass_ref ocls (jni_env, jni_env->FindClass (
"[I"));
787 jobjectArray retval = jni_env->NewObjectArray (idx.
length (), ocls, 0);
789 for (
int i = 0; i < idx.
length (); i++)
796 jint *buf = jni_env->GetIntArrayElements (i_array, 0);
798 for (
int k = 0; k < v.
length (); k++)
801 jni_env->ReleaseIntArrayElements (i_array, buf, 0);
802 jni_env->SetObjectArrayElement (retval, i, i_array);
804 check_exception (jni_env);
817 get_array_elements (JNIEnv* jni_env, jobject jobj,
822 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
826 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
827 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"arraySubsref",
"(Ljava/lang/Object;[[I)Ljava/lang/Object;");
828 resObj = jni_env->CallStaticObjectMethod (helperClass, mID, jobj, jobject (java_idx));
832 retval =
box (jni_env, resObj);
834 retval = check_exception (jni_env);
836 restore_fpu_state ();
842 set_array_elements (JNIEnv* jni_env, jobject jobj,
850 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
854 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
855 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"arraySubsasgn",
856 "(Ljava/lang/Object;[[ILjava/lang/Object;)Ljava/lang/Object;");
857 resObj = jni_env->CallStaticObjectMethod (helperClass, mID,
858 jobj, jobject (java_idx), jobject (rhsObj));
862 retval =
box (jni_env, resObj);
864 retval = check_exception (jni_env);
866 restore_fpu_state ();
872 get_invoke_list (JNIEnv* jni_env, jobject jobj)
874 std::list<std::string> name_list;
878 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj));
879 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls));
880 jmethodID getMethods_ID = jni_env->GetMethodID (ccls,
"getMethods",
"()[Ljava/lang/reflect/Method;");
881 jmethodID getFields_ID = jni_env->GetMethodID (ccls,
"getFields",
"()[Ljava/lang/reflect/Field;");
882 jobjectArray_ref mList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getMethods_ID)));
883 jobjectArray_ref fList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getFields_ID)));
884 int mLen = jni_env->GetArrayLength (mList);
885 int fLen = jni_env->GetArrayLength (fList);
886 jclass_ref mCls (jni_env, jni_env->FindClass (
"java/lang/reflect/Method"));
887 jclass_ref fCls (jni_env, jni_env->FindClass (
"java/lang/reflect/Field"));
888 jmethodID m_getName_ID = jni_env->GetMethodID (mCls,
"getName",
"()Ljava/lang/String;");
889 jmethodID f_getName_ID = jni_env->GetMethodID (fCls,
"getName",
"()Ljava/lang/String;");
891 for (
int i = 0; i < mLen; i++)
893 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i));
894 jstring_ref methName (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (meth, m_getName_ID)));
898 for (
int i = 0; i < fLen; i++)
900 jobject_ref field (jni_env, jni_env->GetObjectArrayElement (fList, i));
901 jstring_ref fieldName (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (field, f_getName_ID)));
905 restore_fpu_state ();
910 return v.
sort (
true);
914 convert_to_string (JNIEnv *jni_env, jobject java_object,
bool force,
char type)
918 if (jni_env && java_object)
920 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/String"));
922 if (jni_env->IsInstanceOf (java_object, cls))
926 cls = jni_env->FindClass (
"[Ljava/lang/String;");
928 if (jni_env->IsInstanceOf (java_object, cls))
930 jobjectArray array =
reinterpret_cast<jobjectArray
> (java_object);
931 int len = jni_env->GetArrayLength (array);
934 for (
int i = 0; i < len; i++)
936 jstring_ref js (jni_env, reinterpret_cast<jstring> (jni_env->GetObjectArrayElement (array, i)));
942 c(i) = check_exception (jni_env);
953 cls = jni_env->FindClass (
"java/lang/Object");
954 jmethodID mID = jni_env->GetMethodID (cls,
"toString",
"()Ljava/lang/String;");
955 jstring_ref js (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (java_object, mID)));
960 retval = check_exception (jni_env);
964 error (
"unable to convert Java object to string");
966 restore_fpu_state ();
972 #define TO_JAVA(obj) dynamic_cast<octave_java*> ((obj).internal_rep ())
975 box (JNIEnv* jni_env, jobject jobj, jclass jcls)
987 cls = jni_env->FindClass (
"java/lang/Number");
988 if (jni_env->IsInstanceOf (jobj, cls))
990 jmethodID m = jni_env->GetMethodID (cls,
"doubleValue",
"()D");
991 retval = jni_env->CallDoubleMethod (jobj, m);
995 cls = jni_env->FindClass (
"java/lang/Boolean");
996 if (jni_env->IsInstanceOf (jobj, cls))
998 jmethodID m = jni_env->GetMethodID (cls,
"booleanValue",
"()Z");
999 retval = (jni_env->CallBooleanMethod (jobj, m) ?
true :
false);
1003 cls = jni_env->FindClass (
"java/lang/String");
1004 if (jni_env->IsInstanceOf (jobj, cls))
1010 cls = jni_env->FindClass (
"java/lang/Character");
1011 if (jni_env->IsInstanceOf (jobj, cls))
1013 jmethodID m = jni_env->GetMethodID (cls,
"charValue",
"()C");
1014 retval = jni_env->CallCharMethod (jobj, m);
1019 if (Vjava_matrix_autoconversion)
1021 cls = find_octave_class (jni_env,
"org/octave/Matrix");
1023 if (jni_env->IsInstanceOf (jobj, cls))
1025 jmethodID mID = jni_env->GetMethodID (cls,
"getDims",
"()[I");
1026 jintArray_ref iv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
1027 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv), 0);
1029 dims.
resize (jni_env->GetArrayLength (jintArray (iv)));
1031 for (
int i = 0; i < dims.
length (); i++)
1032 dims(i) = iv_data[i];
1034 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
1035 mID = jni_env->GetMethodID (cls,
"getClassName",
"()Ljava/lang/String;");
1036 jstring_ref js (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (jobj, mID)));
1043 mID = jni_env->GetMethodID (cls,
"toDouble",
"()[D");
1044 jdoubleArray_ref dv (jni_env, reinterpret_cast<jdoubleArray> (jni_env->CallObjectMethod (jobj, mID)));
1045 jni_env->GetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ());
1049 else if (s ==
"byte")
1051 if (Vjava_unsigned_autoconversion)
1054 mID = jni_env->GetMethodID (cls,
"toByte",
"()[B");
1055 jbyteArray_ref dv (jni_env, reinterpret_cast<jbyteArray> (jni_env->CallObjectMethod (jobj, mID)));
1056 jni_env->GetByteArrayRegion (dv, 0, m.length (),
reinterpret_cast<jbyte *
> (m.fortran_vec ()));
1063 mID = jni_env->GetMethodID (cls,
"toByte",
"()[B");
1064 jbyteArray_ref dv (jni_env, reinterpret_cast<jbyteArray> (jni_env->CallObjectMethod (jobj, mID)));
1065 jni_env->GetByteArrayRegion (dv, 0, m.length (),
reinterpret_cast<jbyte *
> (m.fortran_vec ()));
1070 else if (s ==
"integer")
1072 if (Vjava_unsigned_autoconversion)
1075 mID = jni_env->GetMethodID (cls,
"toInt",
"()[I");
1076 jintArray_ref dv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
1077 jni_env->GetIntArrayRegion (dv, 0, m.length (),
reinterpret_cast<jint *
> (m.fortran_vec ()));
1084 mID = jni_env->GetMethodID (cls,
"toInt",
"()[I");
1085 jintArray_ref dv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
1086 jni_env->GetIntArrayRegion (dv, 0, m.length (),
reinterpret_cast<jint *
> (m.fortran_vec ()));
1094 cls = find_octave_class (jni_env,
"org/octave/OctaveReference");
1095 if (jni_env->IsInstanceOf (jobj, cls))
1097 jmethodID mID = jni_env->GetMethodID (cls,
"getID",
"()I");
1098 int ID = jni_env->CallIntMethod (jobj, mID);
1099 std::map<int,octave_value>::iterator it = octave_ref_map.find (ID);
1101 if (it != octave_ref_map.end ())
1102 retval = it->second;
1116 box_more (JNIEnv* jni_env, jobject jobj, jclass jcls)
1128 cls = jni_env->FindClass (
"[D");
1130 if (jni_env->IsInstanceOf (jobj, cls))
1132 jdoubleArray jarr =
reinterpret_cast<jdoubleArray
> (jobj);
1133 int len = jni_env->GetArrayLength (jarr);
1138 jni_env->GetDoubleArrayRegion (jarr, 0, len, m.fortran_vec ());
1148 cls = jni_env->FindClass (
"[[D");
1150 if (jni_env->IsInstanceOf (jobj, cls))
1152 jobjectArray jarr =
reinterpret_cast<jobjectArray
> (jobj);
1153 int rows = jni_env->GetArrayLength (jarr), cols = 0;
1159 for (
int r = 0; r < rows; r++)
1162 reinterpret_cast<jdoubleArray> (jni_env->GetObjectArrayElement (jarr, r)));
1166 cols = jni_env->GetArrayLength (row);
1169 jni_env->GetDoubleArrayRegion (row, 0, cols, m.
fortran_vec () + r * cols);
1180 cls = jni_env->FindClass (
"[Ljava/lang/String;");
1182 if (jni_env->IsInstanceOf (jobj, cls))
1184 jobjectArray jarr =
reinterpret_cast<jobjectArray
> (jobj);
1185 int len = jni_env->GetArrayLength (jarr);
1188 for (
int i = 0; i < len; i++)
1191 reinterpret_cast<jstring> (jni_env->GetObjectArrayElement (jarr, i)));
1203 restore_fpu_state ();
1219 jcls = jni_env->GetObjectClass (jobj);
1225 jobj = jni_env->NewStringUTF (s.c_str ());
1226 jcls = jni_env->GetObjectClass (jobj);
1233 jclass_ref dcls (jni_env, jni_env->FindClass (
"java/lang/Double"));
1234 jfieldID fid = jni_env->GetStaticFieldID (dcls,
"TYPE",
"Ljava/lang/Class;");
1235 jmethodID mid = jni_env->GetMethodID (dcls,
"<init>",
"(D)V");
1236 jcls =
reinterpret_cast<jclass
> (jni_env->GetStaticObjectField (dcls, fid));
1237 jobj = jni_env->NewObject (dcls, mid, dval);
1242 jclass_ref bcls (jni_env, jni_env->FindClass (
"java/lang/Boolean"));
1243 jfieldID fid = jni_env->GetStaticFieldID (bcls,
"TYPE",
"Ljava/lang/Class;");
1244 jmethodID mid = jni_env->GetMethodID (bcls,
"<init>",
"(Z)V");
1245 jcls =
reinterpret_cast<jclass
> (jni_env->GetStaticObjectField (bcls, fid));
1246 jobj = jni_env->NewObject (bcls, mid, bval);
1251 jclass_ref fcls (jni_env, jni_env->FindClass (
"java/lang/Float"));
1252 jfieldID fid = jni_env->GetStaticFieldID (fcls,
"TYPE",
"Ljava/lang/Class;");
1253 jmethodID mid = jni_env->GetMethodID (fcls,
"<init>",
"(F)V");
1254 jcls =
reinterpret_cast<jclass
> (jni_env->GetStaticObjectField (fcls, fid));
1255 jobj = jni_env->NewObject (fcls, mid, fval);
1261 jclass_ref icls (jni_env, jni_env->FindClass (
"java/lang/Integer"));
1262 jfieldID fid = jni_env->GetStaticFieldID (icls,
"TYPE",
"Ljava/lang/Class;");
1263 jmethodID mid = jni_env->GetMethodID (icls,
"<init>",
"(I)V");
1264 jcls =
reinterpret_cast<jclass
> (jni_env->GetStaticObjectField (icls, fid));
1265 jobj = jni_env->NewObject (icls, mid, ival);
1273 else if (!Vjava_matrix_autoconversion
1279 jdoubleArray dv = jni_env->NewDoubleArray (m.
length ());
1282 jcls = jni_env->GetObjectClass (jobj);
1284 else if (Vjava_matrix_autoconversion
1287 jclass_ref mcls (jni_env, find_octave_class (jni_env,
"org/octave/Matrix"));
1290 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv), 0);
1292 for (
int i = 0; i < dims.
length (); i++)
1293 iv_data[i] = dims(i);
1295 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
1301 jni_env->SetDoubleArrayRegion (jdoubleArray (dv), 0, m.
length (),
1303 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([D[I)V");
1304 jobj = jni_env->NewObject (jclass (mcls), mID, jdoubleArray (dv),
1306 jcls = jni_env->GetObjectClass (jobj);
1312 jni_env->SetByteArrayRegion (jbyteArray (bv), 0, m.
length (),
1314 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([B[I)V");
1315 jobj = jni_env->NewObject (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
1316 jcls = jni_env->GetObjectClass (jobj);
1322 jni_env->SetByteArrayRegion (jbyteArray (bv), 0, m.
length (),
1324 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([B[I)V");
1325 jobj = jni_env->NewObject (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
1326 jcls = jni_env->GetObjectClass (jobj);
1332 jni_env->SetIntArrayRegion (jintArray (v), 0, m.
length (),
1334 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([I[I)V");
1335 jobj = jni_env->NewObject (jclass (mcls), mID, jintArray (v), jintArray (iv));
1336 jcls = jni_env->GetObjectClass (jobj);
1341 error (
"cannot convert matrix of type '%s'", val.
class_name ().c_str ());
1347 jclass_ref scls (jni_env, jni_env->FindClass (
"java/lang/String"));
1348 jobjectArray array = jni_env->NewObjectArray (cellStr.
length (), scls, 0);
1349 for (
int i = 0; i < cellStr.
length (); i++)
1352 jni_env->NewStringUTF (cellStr(i).string_value().c_str ()));
1353 jni_env->SetObjectArrayElement (array, i, jstr);
1356 jcls = jni_env->GetObjectClass (jobj);
1360 jclass rcls = find_octave_class (jni_env,
"org/octave/OctaveReference");
1361 jmethodID mID = jni_env->GetMethodID (rcls,
"<init>",
"(I)V");
1362 int ID = octave_java_refcount++;
1364 jobj = jni_env->NewObject (rcls, mID, ID);
1366 octave_ref_map[ID] = val;
1378 jclass_ref ocls (jni_env, jni_env->FindClass (
"java/lang/Object"));
1379 jclass_ref ccls (jni_env, jni_env->FindClass (
"java/lang/Class"));
1382 jobjs = jni_env->NewObjectArray (args.
length (), ocls, 0);
1385 jclss = jni_env->NewObjectArray (args.
length (), ccls, 0);
1387 for (
int i = 0; i < args.
length (); i++)
1392 if (!
unbox (jni_env, args(i), jobj, jcls))
1398 jni_env->SetObjectArrayElement (jobjs, i, jobj);
1399 jni_env->SetObjectArrayElement (jclss, i, jcls);
1406 get_current_thread_ID (JNIEnv *jni_env)
1410 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/Thread"));
1411 jmethodID mID = jni_env->GetStaticMethodID (cls,
"currentThread",
"()Ljava/lang/Thread;");
1412 jobject_ref jthread (jni_env, jni_env->CallStaticObjectMethod (cls, mID));
1416 jclass_ref jth_cls (jni_env, jni_env->GetObjectClass (jthread));
1417 mID = jni_env->GetMethodID (jth_cls,
"getId",
"()J");
1418 long result = jni_env->CallLongMethod (jthread, mID);
1428 java_event_hook (
void)
1434 jclass_ref cls (current_env, find_octave_class (current_env,
"org/octave/Octave"));
1435 jmethodID mID = current_env->GetStaticMethodID (cls,
"checkPendingAction",
"()V");
1436 current_env->CallStaticVoidMethod (cls, mID);
1438 restore_fpu_state ();
1445 initialize_java (
void)
1457 octave_thread_ID = get_current_thread_ID (current_env);
1460 catch (std::string msg)
1462 error (msg.c_str ());
1465 restore_fpu_state ();
1469 JNIEXPORT jboolean JNICALL
1470 Java_org_octave_Octave_call (JNIEnv *env, jclass, jstring funcName,
1471 jobjectArray argin, jobjectArray argout)
1475 int nargout = env->GetArrayLength (argout);
1476 int nargin = env->GetArrayLength (argin);
1480 for (
int i = 0; i < nargin; i++)
1481 varargin(i) =
box (env, env->GetObjectArrayElement (argin, i), 0);
1483 varargout =
feval (fname, varargin, nargout);
1491 if (
unbox (env, varargout, out_objs, out_clss))
1498 JNIEXPORT
void JNICALL
1499 Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint ID)
1501 octave_ref_map.erase (ID);
1504 JNIEXPORT
void JNICALL
1505 Java_org_octave_Octave_doInvoke (JNIEnv *env, jclass, jint ID,
1508 std::map<int,octave_value>::iterator it = octave_ref_map.find (ID);
1510 if (it != octave_ref_map.end ())
1513 int len = env->GetArrayLength (args);
1516 for (
int i = 0; i < len; i++)
1518 jobject_ref jobj (env, env->GetObjectArrayElement (args, i));
1519 oct_args(i) =
box (env, jobj, 0);
1527 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
1532 feval (fcn, oct_args);
1536 && val.
cell_value()(0).is_function_handle ())
1541 for (
int i=1; i<c.
length (); i++)
1542 oct_args(len+i-1) = c(i);
1545 feval (fcn, oct_args);
1548 error (
"trying to invoke non-invocable object");
1550 END_INTERRUPT_WITH_EXCEPTIONS;
1555 JNIEXPORT
void JNICALL
1556 Java_org_octave_Octave_doEvalString (JNIEnv *env, jclass, jstring cmd)
1563 JNIEXPORT jboolean JNICALL
1564 Java_org_octave_Octave_needThreadedInvokation (JNIEnv *env, jclass)
1566 return (get_current_thread_ID (env) != octave_thread_ID);
1589 if (current_env && java_object)
1590 return compute_array_dimensions (current_env, java_object);
1601 jvm->GetEnv (reinterpret_cast<void **> (&env), JNI_VERSION_1_2);
1608 const std::list<octave_value_list>& idx,
int nargout)
1618 if (type.length () > 1 && type[1] ==
'(')
1623 ovl(0) = (idx.front ())(0);
1624 std::list<octave_value_list>::const_iterator it = idx.begin ();
1626 retval =
feval (std::string (
"javaMethod"), ovl, 1);
1634 ovl(1) = (idx.front ())(0);
1635 retval =
feval (std::string (
"__java_get__"), ovl, 1);
1641 retval = get_array_elements (current_env,
to_java (), idx.front ());
1645 error (
"subsref: Java object cannot be indexed with %c", type[0]);
1649 if (idx.size () > 1 && type.length () > 1)
1650 retval = retval(0).next_subsref (nargout, type, idx, skip);
1657 const std::list<octave_value_list>&idx,
1667 if (type.length () == 1)
1673 ovl(1) = (idx.front ())(0);
1675 feval (
"__java_set__", ovl, 0);
1682 else if (type.length () > 2 && type[1] ==
'(')
1684 std::list<octave_value_list> new_idx;
1685 std::list<octave_value_list>::const_iterator it = idx.begin ();
1686 new_idx.push_back (*it++);
1687 new_idx.push_back (*it++);
1691 std::list<octave_value_list> next_idx (idx);
1692 next_idx.erase (next_idx.begin ());
1693 next_idx.erase (next_idx.begin ());
1694 u(0).subsasgn (type.substr (2), next_idx, rhs);
1702 else if (type[1] ==
'.')
1707 std::list<octave_value_list> next_idx (idx);
1708 next_idx.erase (next_idx.begin ());
1709 u(0).subsasgn (type.substr (1), next_idx, rhs);
1718 error (
"invalid indexing/assignment on Java object");
1724 set_array_elements (current_env,
to_java (), idx.front (), rhs);
1734 error (
"Java object cannot be indexed with %c", type[0]);
1747 return get_invoke_list (current_env,
to_java ());
1758 return convert_to_string (current_env,
to_java (), force, type);
1785 if (
unbox (jni_env, args, arg_objs, arg_types))
1787 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1788 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"invokeMethod",
1789 "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
1790 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1791 jobjectArray_ref resObj (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallStaticObjectMethod (helperClass, mID,
1792 to_java (), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types))));
1794 retval =
box (jni_env, resObj);
1796 retval = check_exception (jni_env);
1799 restore_fpu_state ();
1807 const std::string& class_name,
1808 const std::string& name,
1816 if (
unbox (jni_env, args, arg_objs, arg_types))
1818 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1819 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"invokeStaticMethod",
1820 "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
1821 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1822 jstring_ref clsName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
1823 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
1824 jstring (clsName), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types)));
1826 retval =
box (jni_env, resObj);
1828 retval = check_exception (jni_env);
1831 restore_fpu_state ();
1847 if (
unbox (jni_env, args, arg_objs, arg_types))
1849 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1850 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"invokeConstructor",
1851 "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
1852 jstring_ref clsName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1853 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
1854 jstring (clsName), jobjectArray (arg_objs), jobjectArray (arg_types)));
1859 check_exception (jni_env);
1862 restore_fpu_state ();
1875 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1876 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"getField",
1877 "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
1878 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1879 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
1880 to_java (), jstring (fName)));
1883 retval =
box (jni_env, resObj);
1885 retval = check_exception (jni_env);
1887 restore_fpu_state ();
1895 const std::string& name)
1901 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1902 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"getStaticField",
1903 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
1904 jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
1905 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1906 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
1907 jstring (cName), jstring (fName)));
1909 retval =
box (jni_env, resObj);
1911 retval = check_exception (jni_env);
1913 restore_fpu_state ();
1930 if (
unbox (jni_env, val, jobj, jcls))
1932 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1933 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"setField",
1934 "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
1935 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1936 jni_env->CallStaticObjectMethod (helperClass, mID,
to_java (), jstring (fName), jobject (jobj));
1937 check_exception (jni_env);
1940 restore_fpu_state ();
1957 if (
unbox (jni_env, val, jobj, jcls))
1959 jclass_ref helperClass (jni_env, find_octave_class (jni_env,
"org/octave/ClassHelper"));
1960 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"setStaticField",
1961 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
1962 jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
1963 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
1964 jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName), jstring (fName), jobject (jobj));
1965 check_exception (jni_env);
1968 restore_fpu_state ();
1974 #endif // endif on HAVE_JAVA
1981 @deftypefn {Built-in Function} {} java_init ()\n\
1982 Internal function used @strong{only} when debugging Java interface.\n\
1983 Function will directly call initialize_java() to create an instance of a JVM.\n\
1999 error (
"__java_init__: Octave was not compiled with Java interface");
2006 @deftypefn {Built-in Function} {} java_exit ()\n\
2007 Internal function used @strong{only} when debugging Java interface.\n\
2008 Function will directly call terminate_jvm() to destroy the current JVM\n\
2015 error (
"__java_init__: Octave was not compiled with Java interface");
2023 @deftypefn {Built-in Function} {@var{jobj} =} javaObject (@var{classname})\n\
2024 @deftypefnx {Built-in Function} {@var{jobj} =} javaObject (@var{classname}, @var{arg1}, @dots{})\n\
2025 Create a Java object of class @var{classsname}, by calling the class\n\
2026 constructor with the arguments @var{arg1}, @dots{}\n\
2028 The first example below creates an uninitialized object,\n\
2029 while the second example supplies an initial argument to the constructor.\n\
2033 x = javaObject (\"java.lang.StringBuffer\")\n\
2034 x = javaObject (\"java.lang.StringBuffer\", \"Initial string\")\n\
2038 @seealso{javaMethod, javaArray}\n\
2052 std::string classname = args(0).string_value ();
2056 for (
int i=1; i<args.
length (); i++)
2061 error (
"javaObject: CLASSNAME must be a string");
2069 error (
"javaObject: Octave was not compiled with Java interface");
2084 @deftypefn {Built-in Function} {@var{ret} =} javaMethod (@var{methodname}, @var{obj})\n\
2085 @deftypefnx {Built-in Function} {@var{ret} =} javaMethod (@var{methodname}, @var{obj}, @var{arg1}, @dots{})\n\
2086 Invoke the method @var{methodname} on the Java object @var{obj} with the\n\
2087 arguments @var{arg1}, @dots{} For static methods, @var{obj} can be a string\n\
2088 representing the fully qualified name of the corresponding class. The\n\
2089 function returns the result of the method invocation.\n\
2091 When @var{obj} is a regular Java object, structure-like indexing can be\n\
2092 used as a shortcut syntax. For instance, the two following statements are\n\
2097 ret = javaMethod (\"method1\", x, 1.0, \"a string\")\n\
2098 ret = x.method1 (1.0, \"a string\")\n\
2102 @seealso{methods, javaObject}\n\
2116 std::string methodname = args(0).string_value ();
2120 for (
int i=2; i<args.
length (); i++)
2123 if (args(1).is_java ())
2126 retval = jobj->
do_javaMethod (current_env, methodname, tmp);
2128 else if (args(1).is_string ())
2130 std::string cls = args(1).string_value ();
2134 error (
"javaMethod: OBJ must be a Java object or a string");
2137 error (
"javaMethod: METHODNAME must be a string");
2145 error (
"javaMethod: Octave was not compiled with Java interface");
2159 @deftypefn {Built-in Function} {@var{val} =} __java_get__ (@var{obj}, @var{name})\n\
2160 Get the value of the field @var{name} of the Java object @var{obj}. For\n\
2161 static fields, @var{obj} can be a string representing the fully qualified\n\
2162 name of the corresponding class.\n\
2164 When @var{obj} is a regular Java object, structure-like indexing can be\n\
2165 used as a shortcut syntax. For instance, the two following statements are\n\
2170 __java_get__ (x, \"field1\")\n\
2175 @seealso{__java_set__, javaMethod, javaObject}\n\
2189 std::string name = args(1).string_value ();
2192 if (args(0).is_java ())
2197 else if (args(0).is_string ())
2199 std::string cls = args(0).string_value ();
2203 error (
"__java_get__: OBJ must be a Java object or a string");
2206 error (
"__java_get__: NAME must be a string");
2214 error (
"__java_get__: Octave was not compiled with Java interface");
2221 @deftypefn {Built-in Function} {@var{obj} =} __java_set__ (@var{obj}, @var{name}, @var{val})\n\
2222 Set the value of the field @var{name} of the Java object @var{obj} to\n\
2223 @var{val}. For static fields, @var{obj} can be a string representing the\n\
2224 fully qualified named of the corresponding Java class.\n\
2226 When @var{obj} is a regular Java object, structure-like indexing can be\n\
2227 used as a shortcut syntax. For instance, the two following statements are\n\
2232 __java_set__ (x, \"field1\", val)\n\
2237 @seealso{__java_get__, javaMethod, javaObject}\n\
2251 std::string name = args(1).string_value ();
2254 if (args(0).is_java ())
2257 retval = jobj->
do_java_set (current_env, name, args(2));
2259 else if (args(0).is_string ())
2261 std::string cls = args(0).string_value ();
2265 error (
"__java_set__: OBJ must be a Java object or a string");
2268 error (
"__java_set__: NAME must be a string");
2276 error (
"__java_set__: Octave was not compiled with Java interface");
2283 @deftypefn {Built-in Function} {} java2mat (@var{javaobj})\n\
2284 Undocumented internal function.\n\
2298 if (args(0).is_java ())
2304 retval(0) = args(0);
2312 error (
"java2mat: Octave was not compiled with Java interface");
2317 DEFUN (java_matrix_autoconversion, args, nargout,
2319 @deftypefn {Built-in Function} {@var{val} =} java_matrix_autoconversion ()\n\
2320 @deftypefnx {Built-in Function} {@var{old_val} =} java_matrix_autoconversion (@var{new_val})\n\
2321 @deftypefnx {Built-in Function} {} java_matrix_autoconversion (@var{new_val}, \"local\")\n\
2322 Query or set the internal variable that controls whether Java arrays are\n\
2323 automatically converted to Octave matrices. The default value is false.\n\
2325 When called from inside a function with the @qcode{\"local\"} option, the\n\
2326 variable is changed locally for the function and any subroutines it calls. \n\
2327 The original variable value is restored when exiting the function.\n\
2328 @seealso{java_unsigned_autoconversion, debug_java}\n\
2334 error (
"java_matrix_autoconversion: Octave was not compiled with Java interface");
2339 DEFUN (java_unsigned_autoconversion, args, nargout,
2341 @deftypefn {Built-in Function} {@var{val} =} java_unsigned_autoconversion ()\n\
2342 @deftypefnx {Built-in Function} {@var{old_val} =} java_unsigned_autoconversion (@var{new_val})\n\
2343 @deftypefnx {Built-in Function} {} java_unsigned_autoconversion (@var{new_val}, \"local\")\n\
2344 Query or set the internal variable that controls how integer classes are\n\
2345 converted when @code{java_matrix_autoconversion} is enabled. When enabled,\n\
2346 Java arrays of class Byte or Integer are converted to matrices of class\n\
2347 uint8 or uint32 respectively. The default value is true.\n\
2349 When called from inside a function with the @qcode{\"local\"} option, the\n\
2350 variable is changed locally for the function and any subroutines it calls. \n\
2351 The original variable value is restored when exiting the function.\n\
2352 @seealso{java_matrix_autoconversion, debug_java}\n\
2358 error (
"java_unsigned_autoconversion: Octave was not compiled with Java interface");
2365 @deftypefn {Built-in Function} {@var{val} =} debug_java ()\n\
2366 @deftypefnx {Built-in Function} {@var{old_val} =} debug_java (@var{new_val})\n\
2367 @deftypefnx {Built-in Function} {} debug_java (@var{new_val}, \"local\")\n\
2368 Query or set the internal variable that determines whether extra debugging\n\
2369 information regarding the initialization of the JVM and any Java exceptions\n\
2372 When called from inside a function with the @qcode{\"local\"} option, the\n\
2373 variable is changed locally for the function and any subroutines it calls. \n\
2374 The original variable value is restored when exiting the function.\n\
2375 @seealso{java_matrix_autoconversion, java_unsigned_autoconversion}\n\
2381 error (
"debug_java: Octave was not compiled with Java interface");
2390 @deftypefn {Built-in Function} {} isjava (@var{x})\n\
2391 Return true if @var{x} is a Java object.\n\
2392 @seealso{class, typeinfo, isa, javaObject}\n\
2400 retval = args(0).is_java ();