1 /* src/native/vm/openjdk/jvm.cpp - HotSpot VM interface functions
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #if defined(HAVE_SYS_IOCTL_H)
36 #define BSD_COMP /* Get FIONREAD on Solaris2 */
37 #include <sys/ioctl.h>
40 #include <sys/socket.h>
42 #include <sys/types.h>
44 // Include our JNI header before the JVM headers, because the JVM
45 // headers include jni.h and we want to override the typedefs in
47 #include "native/jni.hpp"
49 // We include jvm_md.h before jvm.h as the latter includes the former.
50 #include INCLUDE_JVM_MD_H
51 #include INCLUDE_JVM_H
53 #include "fdlibm/fdlibm.h"
55 #include "mm/memory.hpp"
57 #include "native/llni.h"
58 #include "native/native.hpp"
60 #include "native/vm/reflection.hpp"
62 #include "native/vm/openjdk/hpi.hpp"
63 #include "native/vm/openjdk/management.hpp"
65 #include "threads/lock.hpp"
66 #include "threads/thread.hpp"
67 #include "threads/threadlist.hpp"
69 #include "toolbox/logging.hpp"
70 #include "toolbox/list.hpp"
72 #include "vm/array.hpp"
74 #if defined(ENABLE_ASSERTION)
75 #include "vm/assertion.hpp"
78 #include "vm/jit/builtin.hpp"
79 #include "vm/classcache.hpp"
80 #include "vm/exceptions.hpp"
81 #include "vm/global.h"
82 #include "vm/globals.hpp"
83 #include "vm/initialize.hpp"
84 #include "vm/javaobjects.hpp"
85 #include "vm/options.h"
87 #include "vm/package.hpp"
88 #include "vm/primitive.hpp"
89 #include "vm/properties.hpp"
90 #include "vm/resolve.hpp"
91 #include "vm/signallocal.hpp"
92 #include "vm/string.hpp"
95 #include "vm/jit/stacktrace.hpp"
98 /* debugging macros ***********************************************************/
102 # define TRACEJVMCALLS(x) \
104 if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) { \
109 # define TRACEJVMCALLSENTER(x) \
111 if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) { \
117 # define TRACEJVMCALLSEXIT(x) \
119 if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) { \
125 # define TRACEJVMCALLSVERBOSE(x) \
127 if (opt_TraceJVMCallsVerbose) { \
132 # define PRINTJVMWARNINGS(x)
134 /* if (opt_PrintJVMWarnings) { \ */
135 /* log_println x; \ */
141 # define TRACEJVMCALLS(x)
142 # define TRACEJVMCALLSENTER(x)
143 # define TRACEJVMCALLSEXIT(x)
144 # define TRACEJVMCALLSVERBOSE(x)
145 # define PRINTJVMWARNINGS(x)
150 // Interface functions are exported as C functions.
153 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
155 if ((intptr_t) count <= 0)
158 return vsnprintf(str, count, fmt, args);
162 int jio_snprintf(char *str, size_t count, const char *fmt, ...)
168 len = jio_vsnprintf(str, count, fmt, ap);
175 int jio_fprintf(FILE* f, const char *fmt, ...)
177 log_println("jio_fprintf: IMPLEMENT ME!");
183 int jio_vfprintf(FILE* f, const char *fmt, va_list args)
185 log_println("jio_vfprintf: IMPLEMENT ME!");
191 int jio_printf(const char *fmt, ...)
193 log_println("jio_printf: IMPLEMENT ME!");
199 /* JVM_GetInterfaceVersion */
201 jint JVM_GetInterfaceVersion()
203 /* This is defined in hotspot/src/share/vm/prims/jvm.h */
205 #define JVM_INTERFACE_VERSION 4
207 return JVM_INTERFACE_VERSION;
211 /* JVM_CurrentTimeMillis */
213 jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
215 TRACEJVMCALLS(("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored));
217 return (jlong) builtin_currenttimemillis();
223 jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
225 TRACEJVMCALLS(("JVM_NanoTime(env=%p, ignored=%p)", env, ignored));
227 return (jlong) builtin_nanotime();
233 void JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length)
238 s = (java_handle_t *) src;
239 d = (java_handle_t *) dst;
241 TRACEJVMCALLSVERBOSE(("JVM_ArrayCopy(env=%p, ignored=%p, src=%p, src_pos=%d, dst=%p, dst_pos=%d, length=%d)", env, ignored, src, src_pos, dst, dst_pos, length));
243 builtin_arraycopy(s, src_pos, d, dst_pos, length);
247 /* JVM_InitProperties */
249 jobject JVM_InitProperties(JNIEnv *env, jobject properties)
254 TRACEJVMCALLS(("JVM_InitProperties(env=%p, properties=%p)", env, properties));
256 h = (java_handle_t *) properties;
258 /* Convert the -XX:MaxDirectMemorySize= command line flag to the
259 sun.nio.MaxDirectMemorySize property. Do this after setting
260 user properties to prevent people from setting the value with a
261 -D option, as requested. */
263 jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
264 VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
266 // Fill the java.util.Properties object.
267 VM::get_current()->get_properties().fill(h);
275 void JVM_Exit(jint code)
277 log_println("JVM_Exit: IMPLEMENT ME!");
283 void JVM_Halt(jint code)
285 TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
292 /* JVM_OnExit(void (*func)) */
294 void JVM_OnExit(void (*func)(void))
296 log_println("JVM_OnExit(void (*func): IMPLEMENT ME!");
304 TRACEJVMCALLS(("JVM_GC()"));
310 /* JVM_MaxObjectInspectionAge */
312 jlong JVM_MaxObjectInspectionAge(void)
314 log_println("JVM_MaxObjectInspectionAge: IMPLEMENT ME!");
320 /* JVM_TraceInstructions */
322 void JVM_TraceInstructions(jboolean on)
324 log_println("JVM_TraceInstructions: IMPLEMENT ME!");
328 /* JVM_TraceMethodCalls */
330 void JVM_TraceMethodCalls(jboolean on)
332 log_println("JVM_TraceMethodCalls: IMPLEMENT ME!");
336 /* JVM_TotalMemory */
338 jlong JVM_TotalMemory(void)
340 TRACEJVMCALLS(("JVM_TotalMemory()"));
342 return gc_get_heap_size();
348 jlong JVM_FreeMemory(void)
350 TRACEJVMCALLS(("JVM_FreeMemory()"));
352 return gc_get_free_bytes();
358 jlong JVM_MaxMemory(void)
360 TRACEJVMCALLS(("JVM_MaxMemory()"));
362 return gc_get_max_heap_size();
366 /* JVM_ActiveProcessorCount */
368 jint JVM_ActiveProcessorCount(void)
370 TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
372 return os::processors_online();
376 /* JVM_FillInStackTrace */
378 void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
380 TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
382 java_handle_bytearray_t* ba = stacktrace_get_current();
387 java_lang_Throwable jlt(receiver, ba);
391 /* JVM_PrintStackTrace */
393 void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
395 log_println("JVM_PrintStackTrace: IMPLEMENT ME!");
399 /* JVM_GetStackTraceDepth */
401 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
403 TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
405 java_lang_Throwable jlt(throwable);
408 exceptions_throw_nullpointerexception();
412 java_handle_bytearray_t* ba = jlt.get_backtrace();
417 // We need a critical section here as the stacktrace structure is
418 // mapped onto a Java byte-array.
422 stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
424 int32_t depth = st->length;
432 /* JVM_GetStackTraceElement */
434 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
436 TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
438 java_lang_Throwable jlt(throwable);
439 java_handle_bytearray_t* ba = jlt.get_backtrace();
441 // XXX We need a critical section here as the stacktrace structure is
442 // mapped onto a Java byte-array.
443 stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
445 return stacktrace_get_StackTraceElement(st, index);
451 jint JVM_IHashCode(JNIEnv* env, jobject handle)
453 TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
455 java_lang_Object o(handle);
457 return o.get_hashcode();
461 /* JVM_MonitorWait */
463 void JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)
465 #if defined(ENABLE_THREADS)
469 TRACEJVMCALLS(("JVM_MonitorWait(env=%p, handle=%p, ms=%ld)", env, handle, ms));
471 /* exceptions_throw_illegalargumentexception("argument out of range"); */
472 exceptions_throw_illegalargumentexception();
476 #if defined(ENABLE_THREADS)
477 o = (java_handle_t *) handle;
479 lock_wait_for_object(o, ms, 0);
484 /* JVM_MonitorNotify */
486 void JVM_MonitorNotify(JNIEnv* env, jobject handle)
488 #if defined(ENABLE_THREADS)
492 TRACEJVMCALLS(("JVM_MonitorNotify(env=%p, handle=%p)", env, handle));
494 #if defined(ENABLE_THREADS)
495 o = (java_handle_t *) handle;
497 lock_notify_object(o);
502 /* JVM_MonitorNotifyAll */
504 void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
506 #if defined(ENABLE_THREADS)
510 TRACEJVMCALLS(("JVM_MonitorNotifyAll(env=%p, handle=%p)", env, handle));
512 #if defined(ENABLE_THREADS)
513 o = (java_handle_t *) handle;
515 lock_notify_all_object(o);
522 jobject JVM_Clone(JNIEnv* env, jobject handle)
524 TRACEJVMCALLS(("JVM_Clone(env=%p, handle=%p)", env, handle));
526 return (jobject) builtin_clone(env, (java_handle_t *) handle);
530 /* JVM_InitializeCompiler */
532 void JVM_InitializeCompiler (JNIEnv *env, jclass compCls)
534 log_println("JVM_InitializeCompiler : IMPLEMENT ME!");
538 /* JVM_IsSilentCompiler */
540 jboolean JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)
542 log_println("JVM_IsSilentCompiler: IMPLEMENT ME!");
548 /* JVM_CompileClass */
550 jboolean JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)
552 log_println("JVM_CompileClass: IMPLEMENT ME!");
558 /* JVM_CompileClasses */
560 jboolean JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)
562 log_println("JVM_CompileClasses: IMPLEMENT ME!");
568 /* JVM_CompilerCommand */
570 jobject JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)
572 log_println("JVM_CompilerCommand: IMPLEMENT ME!");
578 /* JVM_EnableCompiler */
580 void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
582 TRACEJVMCALLS(("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls));
583 PRINTJVMWARNINGS(("JVM_EnableCompiler not supported"));
587 /* JVM_DisableCompiler */
589 void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
591 TRACEJVMCALLS(("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls));
592 PRINTJVMWARNINGS(("JVM_DisableCompiler not supported"));
596 /* JVM_GetLastErrorString */
598 jint JVM_GetLastErrorString(char* buf, int len)
600 TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
602 HPI& hpi = VM::get_current()->get_hpi();
603 return hpi.get_system().GetLastErrorString(buf, len);
609 char *JVM_NativePath(char* path)
611 TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
613 HPI& hpi = VM::get_current()->get_hpi();
614 return hpi.get_file().NativePath(path);
618 /* JVM_GetCallerClass */
620 jclass JVM_GetCallerClass(JNIEnv* env, int depth)
624 TRACEJVMCALLS(("JVM_GetCallerClass(env=%p, depth=%d)", env, depth));
626 c = stacktrace_get_caller_class(depth);
632 /* JVM_FindPrimitiveClass */
634 jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
639 TRACEJVMCALLS(("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s));
642 c = Primitive::get_class_by_name(u);
644 return (jclass) LLNI_classinfo_wrap(c);
648 /* JVM_ResolveClass */
650 void JVM_ResolveClass(JNIEnv* env, jclass cls)
652 TRACEJVMCALLS(("JVM_ResolveClass(env=%p, cls=%p)", env, cls));
653 PRINTJVMWARNINGS(("JVM_ResolveClass not implemented"));
657 /* JVM_FindClassFromClassLoader */
659 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
665 TRACEJVMCALLS(("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError));
667 /* As of now, OpenJDK does not call this function with throwError
670 assert(throwError == false);
672 u = utf_new_char(name);
673 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
675 c = load_class_from_classloader(u, cl);
681 if (!(c->state & CLASS_INITIALIZED))
682 if (!initialize_class(c))
685 return (jclass) LLNI_classinfo_wrap(c);
689 /* JVM_FindClassFromClass */
691 jclass JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, jclass from)
693 log_println("JVM_FindClassFromClass: IMPLEMENT ME!");
699 /* JVM_DefineClass */
701 jclass JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)
703 log_println("JVM_DefineClass: IMPLEMENT ME!");
709 /* JVM_DefineClassWithSource */
711 jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)
717 TRACEJVMCALLS(("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source));
720 u = utf_new_char(name);
724 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
726 /* XXX do something with source */
728 c = class_define(u, cl, len, (uint8_t *) buf, (java_handle_t *) pd);
730 return (jclass) LLNI_classinfo_wrap(c);
734 /* JVM_FindLoadedClass */
736 jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
742 TRACEJVMCALLS(("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name));
744 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
746 u = javastring_toutf((java_handle_t *) name, true);
747 c = classcache_lookup(cl, u);
749 return (jclass) LLNI_classinfo_wrap(c);
753 /* JVM_GetClassName */
755 jstring JVM_GetClassName(JNIEnv *env, jclass cls)
759 TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
761 c = LLNI_classinfo_unwrap(cls);
763 return (jstring) class_get_classname(c);
767 /* JVM_GetClassInterfaces */
769 jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
772 java_handle_objectarray_t *oa;
774 TRACEJVMCALLS(("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls));
776 c = LLNI_classinfo_unwrap(cls);
778 oa = class_get_interfaces(c);
780 return (jobjectArray) oa;
784 /* JVM_GetClassLoader */
786 jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
791 TRACEJVMCALLSENTER(("JVM_GetClassLoader(env=%p, cls=%p)", env, cls));
793 c = LLNI_classinfo_unwrap(cls);
794 cl = class_get_classloader(c);
796 TRACEJVMCALLSEXIT(("->%p", cl));
802 /* JVM_IsInterface */
804 jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
808 TRACEJVMCALLS(("JVM_IsInterface(env=%p, cls=%p)", env, cls));
810 c = LLNI_classinfo_unwrap(cls);
812 return class_is_interface(c);
816 /* JVM_GetClassSigners */
818 jobjectArray JVM_GetClassSigners(JNIEnv *env, jclass cls)
820 log_println("JVM_GetClassSigners: IMPLEMENT ME!");
826 /* JVM_SetClassSigners */
828 void JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)
831 java_handle_objectarray_t *hoa;
833 TRACEJVMCALLS(("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers));
835 c = LLNI_classinfo_unwrap(cls);
837 hoa = (java_handle_objectarray_t *) signers;
839 /* This call is ignored for primitive types and arrays. Signers
840 are only set once, ClassLoader.java, and thus shouldn't be
841 called with an array. Only the bootstrap loader creates
844 if (class_is_primitive(c) || class_is_array(c))
847 LLNI_classinfo_field_set(c, signers, hoa);
851 /* JVM_GetProtectionDomain */
853 jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
857 TRACEJVMCALLS(("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls));
859 c = LLNI_classinfo_unwrap(cls);
862 exceptions_throw_nullpointerexception();
866 /* Primitive types do not have a protection domain. */
868 if (class_is_primitive(c))
871 return (jobject) c->protectiondomain;
875 /* JVM_SetProtectionDomain */
877 void JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain)
879 log_println("JVM_SetProtectionDomain: IMPLEMENT ME!");
883 /* JVM_DoPrivileged */
885 jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
890 java_handle_t *result;
893 TRACEJVMCALLS(("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException));
895 h = (java_handle_t *) action;
896 LLNI_class_get(h, c);
898 if (action == NULL) {
899 exceptions_throw_nullpointerexception();
903 /* lookup run() method (throw no exceptions) */
905 m = class_resolveclassmethod(c, utf_run, utf_void__java_lang_Object, c,
908 if ((m == NULL) || !(m->flags & ACC_PUBLIC) || (m->flags & ACC_STATIC)) {
909 exceptions_throw_internalerror("No run method");
913 /* XXX It seems something with a privileged stack needs to be done
916 result = vm_call_method(m, h);
918 e = exceptions_get_exception();
921 if ( builtin_instanceof(e, class_java_lang_Exception) &&
922 !builtin_instanceof(e, class_java_lang_RuntimeException)) {
923 exceptions_clear_exception();
924 exceptions_throw_privilegedactionexception(e);
930 return (jobject) result;
934 /* JVM_GetInheritedAccessControlContext */
936 jobject JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)
938 log_println("JVM_GetInheritedAccessControlContext: IMPLEMENT ME!");
944 /* JVM_GetStackAccessControlContext */
946 jobject JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)
948 TRACEJVMCALLS(("JVM_GetStackAccessControlContext(env=%p, cls=%p): IMPLEMENT ME!", env, cls));
950 /* XXX All stuff I tested so far works without that function. At
951 some point we have to implement it, but I disable the output
952 for now to make IcedTea happy. */
958 /* JVM_IsArrayClass */
960 jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
964 TRACEJVMCALLS(("JVM_IsArrayClass(env=%p, cls=%p)", env, cls));
966 c = LLNI_classinfo_unwrap(cls);
968 return class_is_array(c);
972 /* JVM_IsPrimitiveClass */
974 jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
978 TRACEJVMCALLS(("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls));
980 c = LLNI_classinfo_unwrap(cls);
982 return class_is_primitive(c);
986 /* JVM_GetComponentType */
988 jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
990 classinfo *component;
993 TRACEJVMCALLS(("JVM_GetComponentType(env=%p, cls=%p)", env, cls));
995 c = LLNI_classinfo_unwrap(cls);
997 component = class_get_componenttype(c);
999 return (jclass) LLNI_classinfo_wrap(component);
1003 /* JVM_GetClassModifiers */
1005 jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
1010 TRACEJVMCALLS(("JVM_GetClassModifiers(env=%p, cls=%p)", env, cls));
1012 c = LLNI_classinfo_unwrap(cls);
1014 flags = class_get_modifiers(c, false);
1020 /* JVM_GetDeclaredClasses */
1022 jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
1025 java_handle_objectarray_t *oa;
1027 TRACEJVMCALLS(("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass));
1029 c = LLNI_classinfo_unwrap(ofClass);
1031 oa = class_get_declaredclasses(c, false);
1033 return (jobjectArray) oa;
1037 /* JVM_GetDeclaringClass */
1039 jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
1044 TRACEJVMCALLS(("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass));
1046 c = LLNI_classinfo_unwrap(ofClass);
1048 dc = class_get_declaringclass(c);
1050 return (jclass) LLNI_classinfo_wrap(dc);
1054 /* JVM_GetClassSignature */
1056 jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
1062 TRACEJVMCALLS(("JVM_GetClassSignature(env=%p, cls=%p)", env, cls));
1064 c = LLNI_classinfo_unwrap(cls);
1066 /* Get the signature of the class. */
1068 u = class_get_signature(c);
1073 /* Convert UTF-string to a Java-string. */
1075 s = javastring_new(u);
1081 /* JVM_GetClassAnnotations */
1083 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
1085 TRACEJVMCALLS(("JVM_GetClassAnnotations(env=%p, cls=%p)", env, cls));
1088 exceptions_throw_nullpointerexception();
1092 classinfo* c = LLNI_classinfo_unwrap(cls);
1094 /* get annotations: */
1095 java_handle_bytearray_t* annotations = class_get_annotations(c);
1097 return (jbyteArray) annotations;
1101 /* JVM_GetFieldAnnotations */
1103 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
1105 TRACEJVMCALLS(("JVM_GetFieldAnnotations(env=%p, field=%p)", env, field));
1107 java_lang_reflect_Field jlrf(field);
1109 if (jlrf.is_null()) {
1110 exceptions_throw_nullpointerexception();
1114 return (jbyteArray) jlrf.get_annotations();
1118 /* JVM_GetMethodAnnotations */
1120 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
1122 TRACEJVMCALLS(("JVM_GetMethodAnnotations(env=%p, method=%p)", env, method));
1124 java_lang_reflect_Method jlrm(method);
1126 if (jlrm.is_null()) {
1127 exceptions_throw_nullpointerexception();
1131 return (jbyteArray) jlrm.get_annotations();
1135 /* JVM_GetMethodDefaultAnnotationValue */
1137 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
1139 TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue(env=%p, method=%p)", env, method));
1141 java_lang_reflect_Method jlrm(method);
1143 if (jlrm.is_null()) {
1144 exceptions_throw_nullpointerexception();
1148 return (jbyteArray) jlrm.get_annotationDefault();
1152 /* JVM_GetMethodParameterAnnotations */
1154 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
1156 TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations(env=%p, method=%p)", env, method));
1158 java_lang_reflect_Method jlrm(method);
1160 if (jlrm.is_null()) {
1161 exceptions_throw_nullpointerexception();
1165 return (jbyteArray) jlrm.get_parameterAnnotations();
1169 /* JVM_GetClassDeclaredFields */
1171 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1174 java_handle_objectarray_t *oa;
1176 TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1178 c = LLNI_classinfo_unwrap(ofClass);
1180 oa = class_get_declaredfields(c, publicOnly);
1182 return (jobjectArray) oa;
1186 /* JVM_GetClassDeclaredMethods */
1188 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1190 TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1192 classinfo* c = LLNI_classinfo_unwrap(ofClass);
1194 java_handle_objectarray_t* oa = class_get_declaredmethods(c, publicOnly);
1196 return (jobjectArray) oa;
1200 /* JVM_GetClassDeclaredConstructors */
1202 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1205 java_handle_objectarray_t *oa;
1207 TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1209 c = LLNI_classinfo_unwrap(ofClass);
1211 oa = class_get_declaredconstructors(c, publicOnly);
1213 return (jobjectArray) oa;
1217 /* JVM_GetClassAccessFlags */
1219 jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
1223 TRACEJVMCALLS(("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls));
1225 c = LLNI_classinfo_unwrap(cls);
1227 /* Primitive type classes have the correct access flags. */
1229 return c->flags & ACC_CLASS_REFLECT_MASK;
1233 /* JVM_GetClassConstantPool */
1235 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
1237 #if defined(ENABLE_ANNOTATIONS)
1238 TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
1240 java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
1241 sun_reflect_ConstantPool cp(h, cls);
1247 return (jobject) cp.get_handle();
1249 log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
1255 /* JVM_ConstantPoolGetSize */
1257 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
1259 classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1261 TRACEJVMCALLS(("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool));
1263 c = LLNI_classinfo_unwrap(jcpool);
1269 /* JVM_ConstantPoolGetClassAt */
1271 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1273 constant_classref *ref; /* classref to the class at constant pool index 'index' */
1274 classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1275 classinfo *result; /* classinfo of the class at constant pool index 'index' */
1277 TRACEJVMCALLS(("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index));
1279 c = LLNI_classinfo_unwrap(jcpool);
1281 ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1284 exceptions_throw_illegalargumentexception();
1288 result = resolve_classref_eager(ref);
1290 return (jclass) LLNI_classinfo_wrap(result);
1294 /* JVM_ConstantPoolGetClassAtIfLoaded */
1296 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1298 constant_classref *ref; /* classref to the class at constant pool index 'index' */
1299 classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1300 classinfo *result; /* classinfo of the class at constant pool index 'index' */
1302 TRACEJVMCALLS(("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index));
1304 c = LLNI_classinfo_unwrap(jcpool);
1306 ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1309 exceptions_throw_illegalargumentexception();
1313 if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result)) {
1317 if ((result == NULL) || !(result->state & CLASS_LOADED)) {
1321 return (jclass) LLNI_classinfo_wrap(result);
1325 /* JVM_ConstantPoolGetMethodAt */
1327 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1329 constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1330 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1332 TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index));
1334 cls = LLNI_classinfo_unwrap(jcpool);
1335 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1338 exceptions_throw_illegalargumentexception();
1342 // Create a new java.lang.reflect.Method Java object.
1343 /* XXX: is that right? or do I have to use resolve_method_*? */
1344 java_lang_reflect_Method jlrm(ref->p.method);
1346 return (jobject) jlrm.get_handle();
1350 /* JVM_ConstantPoolGetMethodAtIfLoaded */
1352 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1354 constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1355 classinfo *c = NULL; /* resolved declaring class of the method */
1356 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1358 TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1360 cls = LLNI_classinfo_unwrap(jcpool);
1361 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1364 exceptions_throw_illegalargumentexception();
1368 if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1372 if (c == NULL || !(c->state & CLASS_LOADED)) {
1376 // Create a new java.lang.reflect.Method Java object.
1377 java_lang_reflect_Method jlrm(ref->p.method);
1379 return (jobject) jlrm.get_handle();
1383 /* JVM_ConstantPoolGetFieldAt */
1385 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1387 constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1388 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1390 TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index));
1392 cls = LLNI_classinfo_unwrap(jcpool);
1393 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1396 exceptions_throw_illegalargumentexception();
1400 // Create a new java.lang.reflect.Field Java object.
1401 java_lang_reflect_Field jlrf(ref->p.field);
1403 return (jobject) jlrf.get_handle();
1407 /* JVM_ConstantPoolGetFieldAtIfLoaded */
1409 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1411 constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1412 classinfo *c; /* resolved declaring class for the field */
1413 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1415 TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1417 cls = LLNI_classinfo_unwrap(jcpool);
1418 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1421 exceptions_throw_illegalargumentexception();
1425 if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1429 if (c == NULL || !(c->state & CLASS_LOADED)) {
1433 // Create a new java.lang.reflect.Field Java object.
1434 java_lang_reflect_Field jlrf(ref->p.field);
1436 return (jobject) jlrf.get_handle();
1440 /* JVM_ConstantPoolGetMemberRefInfoAt */
1442 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1444 log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
1446 /* TODO: implement. (this is yet unused be OpenJDK but, so very low priority) */
1452 /* JVM_ConstantPoolGetIntAt */
1454 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1456 constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
1457 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1459 TRACEJVMCALLS(("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index));
1461 cls = LLNI_classinfo_unwrap(jcpool);
1462 ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
1465 exceptions_throw_illegalargumentexception();
1473 /* JVM_ConstantPoolGetLongAt */
1475 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1477 constant_long *ref; /* reference to the long value in constant pool at index 'index' */
1478 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1480 TRACEJVMCALLS(("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index));
1482 cls = LLNI_classinfo_unwrap(jcpool);
1483 ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
1486 exceptions_throw_illegalargumentexception();
1494 /* JVM_ConstantPoolGetFloatAt */
1496 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1498 constant_float *ref; /* reference to the float value in constant pool at index 'index' */
1499 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1501 TRACEJVMCALLS(("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index));
1503 cls = LLNI_classinfo_unwrap(jcpool);
1504 ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
1507 exceptions_throw_illegalargumentexception();
1515 /* JVM_ConstantPoolGetDoubleAt */
1517 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1519 constant_double *ref; /* reference to the double value in constant pool at index 'index' */
1520 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1522 TRACEJVMCALLS(("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index));
1524 cls = LLNI_classinfo_unwrap(jcpool);
1525 ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
1528 exceptions_throw_illegalargumentexception();
1536 /* JVM_ConstantPoolGetStringAt */
1538 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1540 utf *ref; /* utf object for the string in constant pool at index 'index' */
1541 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1543 TRACEJVMCALLS(("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index));
1545 cls = LLNI_classinfo_unwrap(jcpool);
1546 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
1549 exceptions_throw_illegalargumentexception();
1553 /* XXX: I hope literalstring_new is the right Function. */
1554 return (jstring)literalstring_new(ref);
1558 /* JVM_ConstantPoolGetUTF8At */
1560 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1562 utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
1563 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1565 TRACEJVMCALLS(("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index));
1567 cls = LLNI_classinfo_unwrap(jcpool);
1568 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
1571 exceptions_throw_illegalargumentexception();
1575 /* XXX: I hope literalstring_new is the right Function. */
1576 return (jstring)literalstring_new(ref);
1580 /* JVM_DesiredAssertionStatus */
1582 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
1584 #if defined(ENABLE_ASSERTION)
1589 TRACEJVMCALLS(("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls));
1591 c = LLNI_classinfo_unwrap(cls);
1593 if (c->classloader == NULL) {
1594 status = (jboolean)assertion_system_enabled;
1597 status = (jboolean)assertion_user_enabled;
1600 if (list_assertion_names != NULL) {
1601 for (List<assertion_name_t*>::iterator it = list_assertion_names->begin();
1602 it != list_assertion_names->end(); it++) {
1603 assertion_name_t* item = *it;
1605 name = utf_new_char(item->name);
1606 if (name == c->packagename) {
1607 status = (jboolean)item->enabled;
1609 else if (name == c->name) {
1610 status = (jboolean)item->enabled;
1617 return (jboolean)false;
1622 /* JVM_AssertionStatusDirectives */
1624 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
1626 java_handle_objectarray_t *classes;
1627 java_handle_objectarray_t *packages;
1628 java_booleanarray_t *classEnabled;
1629 java_booleanarray_t *packageEnabled;
1630 #if defined(ENABLE_ASSERTION)
1635 TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
1637 #if defined(ENABLE_ASSERTION)
1638 classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
1640 classes = builtin_anewarray(0, class_java_lang_Object);
1642 if (classes == NULL)
1645 #if defined(ENABLE_ASSERTION)
1646 packages = builtin_anewarray(assertion_package_count, class_java_lang_Object);
1648 packages = builtin_anewarray(0, class_java_lang_Object);
1650 if (packages == NULL)
1653 #if defined(ENABLE_ASSERTION)
1654 classEnabled = builtin_newarray_boolean(assertion_class_count);
1656 classEnabled = builtin_newarray_boolean(0);
1658 if (classEnabled == NULL)
1661 #if defined(ENABLE_ASSERTION)
1662 packageEnabled = builtin_newarray_boolean(assertion_package_count);
1664 packageEnabled = builtin_newarray_boolean(0);
1666 if (packageEnabled == NULL)
1669 #if defined(ENABLE_ASSERTION)
1670 /* initialize arrays */
1672 if (list_assertion_names != NULL) {
1676 for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
1677 assertion_name_t* item = *it;
1679 js = javastring_new_from_ascii(item->name);
1684 if (item->package == false) {
1685 classes->data[i] = js;
1686 classEnabled->data[i] = (jboolean) item->enabled;
1690 packages->data[j] = js;
1691 packageEnabled->data[j] = (jboolean) item->enabled;
1698 /* set instance fields */
1700 java_lang_AssertionStatusDirectives jlasd(classes, classEnabled, packages, packageEnabled);
1702 return (jobject) jlasd.get_handle();
1706 /* JVM_GetClassNameUTF */
1708 const char *JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
1710 log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
1716 /* JVM_GetClassCPTypes */
1718 void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
1720 log_println("JVM_GetClassCPTypes: IMPLEMENT ME!");
1724 /* JVM_GetClassCPEntriesCount */
1726 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
1728 log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
1734 /* JVM_GetClassFieldsCount */
1736 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
1738 log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
1744 /* JVM_GetClassMethodsCount */
1746 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
1748 log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
1754 /* JVM_GetMethodIxExceptionIndexes */
1756 void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)
1758 log_println("JVM_GetMethodIxExceptionIndexes: IMPLEMENT ME!");
1762 /* JVM_GetMethodIxExceptionsCount */
1764 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
1766 log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
1772 /* JVM_GetMethodIxByteCode */
1774 void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)
1776 log_println("JVM_GetMethodIxByteCode: IMPLEMENT ME!");
1780 /* JVM_GetMethodIxByteCodeLength */
1782 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
1784 log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
1790 /* JVM_GetMethodIxExceptionTableEntry */
1792 void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)
1794 log_println("JVM_GetMethodIxExceptionTableEntry: IMPLEMENT ME!");
1798 /* JVM_GetMethodIxExceptionTableLength */
1800 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
1802 log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
1808 /* JVM_GetMethodIxModifiers */
1810 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
1812 log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
1818 /* JVM_GetFieldIxModifiers */
1820 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
1822 log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
1828 /* JVM_GetMethodIxLocalsCount */
1830 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
1832 log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
1838 /* JVM_GetMethodIxArgsSize */
1840 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
1842 log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
1848 /* JVM_GetMethodIxMaxStack */
1850 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
1852 log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
1858 /* JVM_IsConstructorIx */
1860 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
1862 log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
1868 /* JVM_GetMethodIxNameUTF */
1870 const char *JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
1872 log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
1878 /* JVM_GetMethodIxSignatureUTF */
1880 const char *JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
1882 log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
1888 /* JVM_GetCPFieldNameUTF */
1890 const char *JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1892 log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
1898 /* JVM_GetCPMethodNameUTF */
1900 const char *JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1902 log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
1908 /* JVM_GetCPMethodSignatureUTF */
1910 const char *JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1912 log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
1918 /* JVM_GetCPFieldSignatureUTF */
1920 const char *JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1922 log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
1928 /* JVM_GetCPClassNameUTF */
1930 const char *JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1932 log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
1938 /* JVM_GetCPFieldClassNameUTF */
1940 const char *JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1942 log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
1948 /* JVM_GetCPMethodClassNameUTF */
1950 const char *JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1952 log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
1958 /* JVM_GetCPFieldModifiers */
1960 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1962 log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
1968 /* JVM_GetCPMethodModifiers */
1970 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1972 log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
1978 /* JVM_ReleaseUTF */
1980 void JVM_ReleaseUTF(const char *utf)
1982 log_println("JVM_ReleaseUTF: IMPLEMENT ME!");
1986 /* JVM_IsSameClassPackage */
1988 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
1990 log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
1998 /* Taken from: hotspot/src/share/vm/prims/jvm.h */
2001 * JVM I/O error codes
2003 #define JVM_EEXIST -100
2005 jint JVM_Open(const char* fname, jint flags, jint mode)
2009 TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
2011 HPI& hpi = VM::get_current()->get_hpi();
2012 result = hpi.get_file().Open(fname, flags, mode);
2030 jint JVM_Close(jint fd)
2032 TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
2034 HPI& hpi = VM::get_current()->get_hpi();
2035 return hpi.get_file().Close(fd);
2041 jint JVM_Read(jint fd, char* buf, jint nbytes)
2043 TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
2045 HPI& hpi = VM::get_current()->get_hpi();
2046 return (jint) hpi.get_file().Read(fd, buf, nbytes);
2052 jint JVM_Write(jint fd, char* buf, jint nbytes)
2054 TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
2056 HPI& hpi = VM::get_current()->get_hpi();
2057 return (jint) hpi.get_file().Write(fd, buf, nbytes);
2063 jint JVM_Available(jint fd, jlong* pbytes)
2065 TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
2067 HPI& hpi = VM::get_current()->get_hpi();
2068 return hpi.get_file().Available(fd, pbytes);
2074 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
2076 TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
2078 HPI& hpi = VM::get_current()->get_hpi();
2079 return hpi.get_file().Seek(fd, (off_t) offset, whence);
2085 jint JVM_SetLength(jint fd, jlong length)
2087 TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
2089 HPI& hpi = VM::get_current()->get_hpi();
2090 return hpi.get_file().SetLength(fd, length);
2096 jint JVM_Sync(jint fd)
2098 TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
2100 HPI& hpi = VM::get_current()->get_hpi();
2101 return hpi.get_file().Sync(fd);
2105 /* JVM_StartThread */
2107 void JVM_StartThread(JNIEnv* env, jobject jthread)
2109 TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
2111 threads_thread_start((java_handle_t *) jthread);
2115 /* JVM_StopThread */
2117 void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
2119 log_println("JVM_StopThread: Deprecated. Not implemented.");
2123 /* JVM_IsThreadAlive */
2125 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
2131 TRACEJVMCALLS(("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread));
2133 h = (java_handle_t *) jthread;
2134 t = thread_get_thread(h);
2136 /* The threadobject is null when a thread is created in Java. */
2141 result = threads_thread_is_alive(t);
2147 /* JVM_SuspendThread */
2149 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
2151 log_println("JVM_SuspendThread: Deprecated. Not implemented.");
2155 /* JVM_ResumeThread */
2157 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
2159 log_println("JVM_ResumeThread: Deprecated. Not implemented.");
2163 /* JVM_SetThreadPriority */
2165 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
2170 TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
2172 h = (java_handle_t *) jthread;
2173 t = thread_get_thread(h);
2175 /* The threadobject is null when a thread is created in Java. The
2176 priority is set later during startup. */
2181 threads_set_thread_priority(t->tid, prio);
2187 void JVM_Yield(JNIEnv *env, jclass threadClass)
2189 TRACEJVMCALLS(("JVM_Yield(env=%p, threadClass=%p)", env, threadClass));
2197 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
2199 TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
2201 threads_sleep(millis, 0);
2205 /* JVM_CurrentThread */
2207 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
2211 TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
2213 o = thread_get_current_object();
2219 /* JVM_CountStackFrames */
2221 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
2223 log_println("JVM_CountStackFrames: Deprecated. Not implemented.");
2231 void JVM_Interrupt(JNIEnv* env, jobject jthread)
2236 TRACEJVMCALLS(("JVM_Interrupt(env=%p, jthread=%p)", env, jthread));
2238 h = (java_handle_t *) jthread;
2239 t = thread_get_thread(h);
2241 /* The threadobject is null when a thread is created in Java. */
2246 threads_thread_interrupt(t);
2250 /* JVM_IsInterrupted */
2252 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2256 jboolean interrupted;
2258 TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
2260 h = (java_handle_t *) jthread;
2261 t = thread_get_thread(h);
2263 /* The threadobject is null when a thread is created in Java. */
2268 interrupted = thread_is_interrupted(t);
2270 if (interrupted && clear_interrupted)
2271 thread_set_interrupted(t, false);
2279 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2284 TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
2286 h = (java_handle_t *) obj;
2289 exceptions_throw_nullpointerexception();
2293 result = lock_is_held_by_current_thread(h);
2299 /* JVM_DumpAllStacks */
2301 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2303 log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2307 /* JVM_CurrentLoadedClass */
2309 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2311 log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2317 /* JVM_CurrentClassLoader */
2319 jobject JVM_CurrentClassLoader(JNIEnv *env)
2321 /* XXX if a method in a class in a trusted loader is in a
2322 doPrivileged, return NULL */
2324 log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2330 /* JVM_GetClassContext */
2332 jobjectArray JVM_GetClassContext(JNIEnv *env)
2334 TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
2336 return (jobjectArray) stacktrace_getClassContext();
2340 /* JVM_ClassDepth */
2342 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2344 log_println("JVM_ClassDepth: IMPLEMENT ME!");
2350 /* JVM_ClassLoaderDepth */
2352 jint JVM_ClassLoaderDepth(JNIEnv *env)
2354 log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2360 /* JVM_GetSystemPackage */
2362 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2368 TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
2370 /* s = Package::find(name); */
2371 u = javastring_toutf((java_handle_t *) name, false);
2373 result = Package::find(u);
2376 s = javastring_new(result);
2384 /* JVM_GetSystemPackages */
2386 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2388 log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2394 /* JVM_AllocateNewObject */
2396 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2398 log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2404 /* JVM_AllocateNewArray */
2406 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2408 log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2414 /* JVM_LatestUserDefinedLoader */
2416 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2420 TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
2422 cl = stacktrace_first_nonnull_classloader();
2424 return (jobject) cl;
2428 /* JVM_LoadClass0 */
2430 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2432 log_println("JVM_LoadClass0: IMPLEMENT ME!");
2438 /* JVM_GetArrayLength */
2440 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2444 TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
2446 a = (java_handle_t *) arr;
2448 return array_length_get(a);
2452 /* JVM_GetArrayElement */
2454 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2459 TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
2461 a = (java_handle_t *) arr;
2463 /* if (!class_is_array(a->objheader.vftbl->class)) { */
2464 /* exceptions_throw_illegalargumentexception(); */
2468 o = array_element_get(a, index);
2474 /* JVM_GetPrimitiveArrayElement */
2476 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2480 log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2488 /* JVM_SetArrayElement */
2490 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2493 java_handle_t *value;
2495 TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
2497 a = (java_handle_t *) arr;
2498 value = (java_handle_t *) val;
2500 array_element_set(a, index, value);
2504 /* JVM_SetPrimitiveArrayElement */
2506 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2508 log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2514 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2519 java_handle_objectarray_t *oa;
2521 TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
2523 if (eltClass == NULL) {
2524 exceptions_throw_nullpointerexception();
2528 /* NegativeArraySizeException is checked in builtin_newarray. */
2530 c = LLNI_classinfo_unwrap(eltClass);
2532 /* Create primitive or object array. */
2534 if (class_is_primitive(c)) {
2535 pc = Primitive::get_arrayclass_by_name(c->name);
2537 /* void arrays are not allowed. */
2540 exceptions_throw_illegalargumentexception();
2544 a = builtin_newarray(length, pc);
2549 oa = builtin_anewarray(length, c);
2551 return (jobject) oa;
2556 /* JVM_NewMultiArray */
2558 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2561 java_handle_intarray_t *ia;
2567 java_handle_objectarray_t *a;
2569 TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
2571 if (eltClass == NULL) {
2572 exceptions_throw_nullpointerexception();
2576 /* NegativeArraySizeException is checked in builtin_newarray. */
2578 c = LLNI_classinfo_unwrap(eltClass);
2580 ia = (java_handle_intarray_t *) dim;
2582 length = array_length_get((java_handle_t *) ia);
2584 /* We check here for exceptions thrown in array_length_get,
2585 otherwise these exceptions get overwritten by the following
2586 IllegalArgumentException. */
2591 if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
2592 exceptions_throw_illegalargumentexception();
2596 /* XXX This is just a quick hack to get it working. */
2598 dims = MNEW(long, length);
2600 for (i = 0; i < length; i++) {
2601 value = LLNI_array_direct(ia, i);
2602 dims[i] = (long) value;
2605 /* Create an array-class if necessary. */
2607 if (class_is_primitive(c)) {
2608 ac = Primitive::get_arrayclass_by_name(c->name);
2610 // Arrays of void are not allowed.
2612 exceptions_throw_illegalargumentexception();
2617 ac = class_multiarray_of((length - 1), ac, true);
2620 ac = class_multiarray_of(length, c, true);
2625 /* Allocate a new array on the heap. */
2627 a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
2633 /* JVM_InitializeSocketLibrary */
2635 jint JVM_InitializeSocketLibrary()
2637 TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
2639 HPI& hpi = VM::get_current()->get_hpi();
2640 return hpi.initialize_socket_library();
2646 jint JVM_Socket(jint domain, jint type, jint protocol)
2648 TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
2650 return os::socket(domain, type, protocol);
2654 /* JVM_SocketClose */
2656 jint JVM_SocketClose(jint fd)
2658 TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
2660 return os::close(fd);
2664 /* JVM_SocketShutdown */
2666 jint JVM_SocketShutdown(jint fd, jint howto)
2668 TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
2670 return os::shutdown(fd, howto);
2676 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2678 log_println("JVM_Recv: IMPLEMENT ME!");
2686 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2688 TRACEJVMCALLSENTER(("JVM_Send(fd=%d, buf=%p, nBytes=%d, flags=%d", fd, buf, nBytes, flags));
2690 int result = os::send(fd, buf, nBytes, flags);
2692 TRACEJVMCALLSEXIT(("->%d", result));
2700 jint JVM_Timeout(int fd, long timeout)
2702 log_println("JVM_Timeout: IMPLEMENT ME!");
2710 jint JVM_Listen(jint fd, jint count)
2712 TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
2714 return os::listen(fd, count);
2720 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2722 TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
2724 return os::connect(fd, him, len);
2730 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2732 log_println("JVM_Bind: IMPLEMENT ME!");
2740 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2742 TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
2744 return os::accept(fd, him, (socklen_t *) len);
2750 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2752 log_println("JVM_RecvFrom: IMPLEMENT ME!");
2758 /* JVM_GetSockName */
2760 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2762 TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
2764 return os::getsockname(fd, him, (socklen_t *) len);
2770 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2772 log_println("JVM_SendTo: IMPLEMENT ME!");
2778 /* JVM_SocketAvailable */
2780 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2782 #if defined(FIONREAD)
2786 TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
2790 result = ioctl(fd, FIONREAD, &bytes);
2799 # error FIONREAD not defined
2804 /* JVM_GetSockOpt */
2806 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2808 TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
2810 return os::getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
2814 /* JVM_SetSockOpt */
2816 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2818 TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
2820 return os::setsockopt(fd, level, optname, optval, optlen);
2824 /* JVM_GetHostName */
2826 int JVM_GetHostName(char *name, int namelen)
2830 TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
2832 result = os::gethostname(name, namelen);
2834 TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
2840 /* JVM_GetHostByAddr */
2842 struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
2844 log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2850 /* JVM_GetHostByName */
2852 struct hostent *JVM_GetHostByName(char* name)
2854 log_println("JVM_GetHostByName: IMPLEMENT ME!");
2860 /* JVM_GetProtoByName */
2862 struct protoent *JVM_GetProtoByName(char* name)
2864 log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2870 /* JVM_LoadLibrary */
2872 void* JVM_LoadLibrary(const char* name)
2874 TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
2876 utf* u = utf_new_char(name);
2878 NativeLibrary nl(u);
2879 void* handle = nl.open();
2881 TRACEJVMCALLSEXIT(("->%p", handle));
2887 /* JVM_UnloadLibrary */
2889 void JVM_UnloadLibrary(void* handle)
2891 TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
2893 NativeLibrary nl(handle);
2898 /* JVM_FindLibraryEntry */
2900 void *JVM_FindLibraryEntry(void* handle, const char* name)
2904 TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
2906 HPI& hpi = VM::get_current()->get_hpi();
2907 symbol = hpi.get_library().FindLibraryEntry(handle, name);
2909 TRACEJVMCALLSEXIT(("->%p", symbol));
2917 jboolean JVM_IsNaN(jdouble d)
2921 TRACEJVMCALLSENTER(("JVM_IsNaN(d=%f)", d));
2925 TRACEJVMCALLSEXIT(("->%d", result));
2931 /* JVM_IsSupportedJNIVersion */
2933 jboolean JVM_IsSupportedJNIVersion(jint version)
2935 TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
2937 return jni_version_check(version);
2941 /* JVM_InternString */
2943 jstring JVM_InternString(JNIEnv *env, jstring str)
2945 TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
2947 return (jstring) javastring_intern((java_handle_t *) str);
2951 /* JVM_RawMonitorCreate */
2953 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
2955 TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
2957 Mutex* m = new Mutex();
2963 /* JVM_RawMonitorDestroy */
2965 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void* mon)
2967 TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
2969 delete ((Mutex*) mon);
2973 /* JVM_RawMonitorEnter */
2975 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void* mon)
2977 TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
2979 ((Mutex*) mon)->lock();
2985 /* JVM_RawMonitorExit */
2987 JNIEXPORT void JNICALL JVM_RawMonitorExit(void* mon)
2989 TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
2991 ((Mutex*) mon)->unlock();
2995 /* JVM_SetPrimitiveFieldValues */
2997 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
2999 log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
3003 /* JVM_GetPrimitiveFieldValues */
3005 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3007 log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
3011 /* JVM_AccessVMBooleanFlag */
3013 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
3015 log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
3021 /* JVM_AccessVMIntFlag */
3023 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
3025 log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
3031 /* JVM_VMBreakPoint */
3033 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
3035 log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
3039 /* JVM_GetClassFields */
3041 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
3043 log_println("JVM_GetClassFields: IMPLEMENT ME!");
3049 /* JVM_GetClassMethods */
3051 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
3053 log_println("JVM_GetClassMethods: IMPLEMENT ME!");
3059 /* JVM_GetClassConstructors */
3061 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
3063 log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
3069 /* JVM_GetClassField */
3071 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
3073 log_println("JVM_GetClassField: IMPLEMENT ME!");
3079 /* JVM_GetClassMethod */
3081 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
3083 log_println("JVM_GetClassMethod: IMPLEMENT ME!");
3089 /* JVM_GetClassConstructor */
3091 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
3093 log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
3099 /* JVM_NewInstance */
3101 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
3103 log_println("JVM_NewInstance: IMPLEMENT ME!");
3111 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
3113 log_println("JVM_GetField: IMPLEMENT ME!");
3119 /* JVM_GetPrimitiveField */
3121 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
3125 log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
3135 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
3137 log_println("JVM_SetField: IMPLEMENT ME!");
3141 /* JVM_SetPrimitiveField */
3143 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
3145 log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
3149 /* JVM_InvokeMethod */
3151 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
3153 TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
3155 java_lang_reflect_Method jlrm(method);
3157 java_handle_t* result = jlrm.invoke((java_handle_t*) obj, (java_handle_objectarray_t*) args0);
3159 return (jobject) result;
3163 /* JVM_NewInstanceFromConstructor */
3165 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
3167 TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
3169 java_lang_reflect_Constructor jlrc(con);
3170 java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args0);
3176 /* JVM_SupportsCX8 */
3178 jboolean JVM_SupportsCX8()
3180 TRACEJVMCALLS(("JVM_SupportsCX8()"));
3190 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
3192 log_println("JVM_CX8Field: IMPLEMENT ME!");
3198 /* JVM_GetAllThreads */
3200 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
3202 // Get a list of all active threads.
3203 list<threadobject*> active_threads;
3204 ThreadList::get_active_threads(active_threads);
3206 // Allocate array to hold the java.lang.Thread objects.
3207 int32_t length = active_threads.size();
3208 java_handle_objectarray_t* oa = builtin_anewarray(length, class_java_lang_Thread);
3213 // Iterate over all threads (which were active just a second ago).
3215 for (List<threadobject*>::iterator it = active_threads.begin(); it != active_threads.end(); it++) {
3216 threadobject* t = *it;
3218 java_handle_t* h = thread_get_object(t);
3221 array_objectarray_element_set(oa, index, h);
3230 /* JVM_DumpThreads */
3232 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
3236 TRACEJVMCALLS(("JVM_DumpThreads((env=%p, threadClass=%p, threads=%p)", env, threadClass, threads));
3238 if (threads == NULL) {
3239 exceptions_throw_nullpointerexception();
3243 // Get length of the threads array.
3244 int32_t length = array_length_get((java_handle_t*) threads);
3247 exceptions_throw_illegalargumentexception();
3251 // Allocate array to hold stacktraces.
3252 classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
3253 java_handle_objectarray_t* oas = builtin_anewarray(length, arrayclass);
3259 // Iterate over all passed thread objects.
3260 for (i = 0; i < length; i++) {
3261 java_handle_t* thread = array_objectarray_element_get(threads, i);
3263 // Get thread for the given thread object.
3264 threadobject* t = thread_get_thread(thread);
3266 // The threadobject is null when a thread is created in Java.
3270 // Get stacktrace for given thread.
3271 stacktrace_t* st = stacktrace_get_of_thread(t);
3273 // Convert stacktrace into array of StackTraceElements.
3274 java_handle_objectarray_t* oa = stacktrace_get_StackTraceElements(st);
3279 array_objectarray_element_set(oas, i, (java_handle_t*) oa);
3286 /* JVM_GetManagement */
3288 void *JVM_GetManagement(jint version)
3290 TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
3292 return Management::get_jmm_interface(version);
3296 /* JVM_InitAgentProperties */
3298 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
3300 log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
3306 /* JVM_GetEnclosingMethodInfo */
3308 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
3312 java_handle_objectarray_t *oa;
3314 TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
3316 c = LLNI_classinfo_unwrap(ofClass);
3318 if ((c == NULL) || class_is_primitive(c))
3321 m = class_get_enclosingmethod_raw(c);
3326 oa = builtin_anewarray(3, class_java_lang_Object);
3331 array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
3332 array_objectarray_element_set(oa, 1, javastring_new(m->name));
3333 array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
3335 return (jobjectArray) oa;
3339 /* JVM_GetThreadStateValues */
3341 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
3343 java_handle_intarray_t *ia;
3345 TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
3346 env, javaThreadState));
3348 /* If new thread states are added in future JDK and VM versions,
3349 this should check if the JDK version is compatible with thread
3350 states supported by the VM. Return NULL if not compatible.
3352 This function must map the VM java_lang_Thread::ThreadStatus
3353 to the Java thread state that the JDK supports. */
3355 switch (javaThreadState) {
3356 case THREAD_STATE_NEW:
3357 ia = builtin_newarray_int(1);
3362 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
3365 case THREAD_STATE_RUNNABLE:
3366 ia = builtin_newarray_int(1);
3371 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
3374 case THREAD_STATE_BLOCKED:
3375 ia = builtin_newarray_int(1);
3380 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
3383 case THREAD_STATE_WAITING:
3384 ia = builtin_newarray_int(2);
3389 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
3390 array_intarray_element_set(ia, 1, THREAD_STATE_PARKED);
3393 case THREAD_STATE_TIMED_WAITING:
3394 ia = builtin_newarray_int(2);
3399 /* XXX Not sure about that one. */
3400 /* array_intarray_element_set(ia, 0, SLEEPING); */
3401 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
3402 array_intarray_element_set(ia, 1, THREAD_STATE_TIMED_PARKED);
3405 case THREAD_STATE_TERMINATED:
3406 ia = builtin_newarray_int(1);
3411 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
3415 /* Unknown state - probably incompatible JDK version */
3419 return (jintArray) ia;
3423 /* JVM_GetThreadStateNames */
3425 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
3427 java_handle_intarray_t *ia;
3428 java_handle_objectarray_t *oa;
3431 TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
3432 env, javaThreadState, values));
3434 ia = (java_handle_intarray_t *) values;
3436 /* If new thread states are added in future JDK and VM versions,
3437 this should check if the JDK version is compatible with thread
3438 states supported by the VM. Return NULL if not compatible.
3440 This function must map the VM java_lang_Thread::ThreadStatus
3441 to the Java thread state that the JDK supports. */
3443 if (values == NULL) {
3444 exceptions_throw_nullpointerexception();
3448 switch (javaThreadState) {
3449 case THREAD_STATE_NEW:
3450 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
3452 oa = builtin_anewarray(1, class_java_lang_String);
3457 s = javastring_new(utf_new_char("NEW"));
3462 array_objectarray_element_set(oa, 0, s);
3465 case THREAD_STATE_RUNNABLE:
3466 oa = builtin_anewarray(1, class_java_lang_String);
3471 s = javastring_new(utf_new_char("RUNNABLE"));
3476 array_objectarray_element_set(oa, 0, s);
3479 case THREAD_STATE_BLOCKED:
3480 oa = builtin_anewarray(1, class_java_lang_String);
3485 s = javastring_new(utf_new_char("BLOCKED"));
3490 array_objectarray_element_set(oa, 0, s);
3493 case THREAD_STATE_WAITING:
3494 oa = builtin_anewarray(2, class_java_lang_String);
3499 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
3504 array_objectarray_element_set(oa, 0, s);
3506 s = javastring_new(utf_new_char("WAITING.PARKED"));
3511 array_objectarray_element_set(oa, 1, s);
3514 case THREAD_STATE_TIMED_WAITING:
3515 oa = builtin_anewarray(2, class_java_lang_String);
3520 /* s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
3521 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
3526 array_objectarray_element_set(oa, 0, s);
3528 s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
3533 array_objectarray_element_set(oa, 1, s);
3536 case THREAD_STATE_TERMINATED:
3537 oa = builtin_anewarray(1, class_java_lang_String);
3542 s = javastring_new(utf_new_char("TERMINATED"));
3547 array_objectarray_element_set(oa, 0, s);
3551 /* Unknown state - probably incompatible JDK version */
3555 return (jobjectArray) oa;
3559 /* JVM_GetVersionInfo */
3561 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3563 log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3567 /* OS: JVM_RegisterSignal */
3569 void *JVM_RegisterSignal(jint sig, void *handler)
3571 functionptr newHandler;
3573 TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
3575 if (handler == (void *) 2)
3576 newHandler = (functionptr) signal_thread_handler;
3578 newHandler = (functionptr) (uintptr_t) handler;
3585 /* These signals are already used by the VM. */
3589 /* This signal is used by the VM to dump thread stacks unless
3590 ReduceSignalUsage is set, in which case the user is allowed
3591 to set his own _native_ handler for this signal; thus, in
3592 either case, we do not allow JVM_RegisterSignal to change
3602 signal_register_signal(sig, newHandler, SA_RESTART | SA_SIGINFO);
3604 /* XXX Should return old handler. */
3610 /* OS: JVM_RaiseSignal */
3612 jboolean JVM_RaiseSignal(jint sig)
3614 log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3620 /* OS: JVM_FindSignal */
3622 jint JVM_FindSignal(const char *name)
3624 TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
3626 #if defined(__LINUX__)
3627 if (strcmp(name, "HUP") == 0)
3630 if (strcmp(name, "INT") == 0)
3633 if (strcmp(name, "TERM") == 0)
3635 #elif defined(__SOLARIS__)
3638 if (os::str2sig(name, &signum) == -1)
3643 # error Not implemented for this OS.
3653 * These are local overrides for various environment variables in Emacs.
3654 * Please do not remove this and leave it at the end of the file, where
3655 * Emacs will automagically detect them.
3656 * ---------------------------------------------------------------------
3659 * indent-tabs-mode: t
3663 * vim:noexpandtab:sw=4:ts=4: