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. The
2137 priority is set later during startup. */
2142 result = threads_thread_is_alive(t);
2148 /* JVM_SuspendThread */
2150 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
2152 log_println("JVM_SuspendThread: Deprecated. Not implemented.");
2156 /* JVM_ResumeThread */
2158 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
2160 log_println("JVM_ResumeThread: Deprecated. Not implemented.");
2164 /* JVM_SetThreadPriority */
2166 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
2171 TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
2173 h = (java_handle_t *) jthread;
2174 t = thread_get_thread(h);
2176 /* The threadobject is null when a thread is created in Java. The
2177 priority is set later during startup. */
2182 threads_set_thread_priority(t->tid, prio);
2188 void JVM_Yield(JNIEnv *env, jclass threadClass)
2190 TRACEJVMCALLS(("JVM_Yield(env=%p, threadClass=%p)", env, threadClass));
2198 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
2200 TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
2202 threads_sleep(millis, 0);
2206 /* JVM_CurrentThread */
2208 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
2212 TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
2214 o = thread_get_current_object();
2220 /* JVM_CountStackFrames */
2222 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
2224 log_println("JVM_CountStackFrames: Deprecated. Not implemented.");
2232 void JVM_Interrupt(JNIEnv* env, jobject jthread)
2237 TRACEJVMCALLS(("JVM_Interrupt(env=%p, jthread=%p)", env, jthread));
2239 h = (java_handle_t *) jthread;
2240 t = thread_get_thread(h);
2245 threads_thread_interrupt(t);
2249 /* JVM_IsInterrupted */
2251 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2255 jboolean interrupted;
2257 TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
2259 h = (java_handle_t *) jthread;
2260 t = thread_get_thread(h);
2262 interrupted = thread_is_interrupted(t);
2264 if (interrupted && clear_interrupted)
2265 thread_set_interrupted(t, false);
2273 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2278 TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
2280 h = (java_handle_t *) obj;
2283 exceptions_throw_nullpointerexception();
2287 result = lock_is_held_by_current_thread(h);
2293 /* JVM_DumpAllStacks */
2295 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2297 log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2301 /* JVM_CurrentLoadedClass */
2303 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2305 log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2311 /* JVM_CurrentClassLoader */
2313 jobject JVM_CurrentClassLoader(JNIEnv *env)
2315 /* XXX if a method in a class in a trusted loader is in a
2316 doPrivileged, return NULL */
2318 log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2324 /* JVM_GetClassContext */
2326 jobjectArray JVM_GetClassContext(JNIEnv *env)
2328 TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
2330 return (jobjectArray) stacktrace_getClassContext();
2334 /* JVM_ClassDepth */
2336 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2338 log_println("JVM_ClassDepth: IMPLEMENT ME!");
2344 /* JVM_ClassLoaderDepth */
2346 jint JVM_ClassLoaderDepth(JNIEnv *env)
2348 log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2354 /* JVM_GetSystemPackage */
2356 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2362 TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
2364 /* s = Package::find(name); */
2365 u = javastring_toutf((java_handle_t *) name, false);
2367 result = Package::find(u);
2370 s = javastring_new(result);
2378 /* JVM_GetSystemPackages */
2380 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2382 log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2388 /* JVM_AllocateNewObject */
2390 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2392 log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2398 /* JVM_AllocateNewArray */
2400 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2402 log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2408 /* JVM_LatestUserDefinedLoader */
2410 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2414 TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
2416 cl = stacktrace_first_nonnull_classloader();
2418 return (jobject) cl;
2422 /* JVM_LoadClass0 */
2424 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2426 log_println("JVM_LoadClass0: IMPLEMENT ME!");
2432 /* JVM_GetArrayLength */
2434 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2438 TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
2440 a = (java_handle_t *) arr;
2442 return array_length_get(a);
2446 /* JVM_GetArrayElement */
2448 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2453 TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
2455 a = (java_handle_t *) arr;
2457 /* if (!class_is_array(a->objheader.vftbl->class)) { */
2458 /* exceptions_throw_illegalargumentexception(); */
2462 o = array_element_get(a, index);
2468 /* JVM_GetPrimitiveArrayElement */
2470 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2474 log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2482 /* JVM_SetArrayElement */
2484 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2487 java_handle_t *value;
2489 TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
2491 a = (java_handle_t *) arr;
2492 value = (java_handle_t *) val;
2494 array_element_set(a, index, value);
2498 /* JVM_SetPrimitiveArrayElement */
2500 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2502 log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2508 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2513 java_handle_objectarray_t *oa;
2515 TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
2517 if (eltClass == NULL) {
2518 exceptions_throw_nullpointerexception();
2522 /* NegativeArraySizeException is checked in builtin_newarray. */
2524 c = LLNI_classinfo_unwrap(eltClass);
2526 /* Create primitive or object array. */
2528 if (class_is_primitive(c)) {
2529 pc = Primitive::get_arrayclass_by_name(c->name);
2531 /* void arrays are not allowed. */
2534 exceptions_throw_illegalargumentexception();
2538 a = builtin_newarray(length, pc);
2543 oa = builtin_anewarray(length, c);
2545 return (jobject) oa;
2550 /* JVM_NewMultiArray */
2552 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2555 java_handle_intarray_t *ia;
2561 java_handle_objectarray_t *a;
2563 TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
2565 if (eltClass == NULL) {
2566 exceptions_throw_nullpointerexception();
2570 /* NegativeArraySizeException is checked in builtin_newarray. */
2572 c = LLNI_classinfo_unwrap(eltClass);
2574 ia = (java_handle_intarray_t *) dim;
2576 length = array_length_get((java_handle_t *) ia);
2578 /* We check here for exceptions thrown in array_length_get,
2579 otherwise these exceptions get overwritten by the following
2580 IllegalArgumentException. */
2585 if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
2586 exceptions_throw_illegalargumentexception();
2590 /* XXX This is just a quick hack to get it working. */
2592 dims = MNEW(long, length);
2594 for (i = 0; i < length; i++) {
2595 value = LLNI_array_direct(ia, i);
2596 dims[i] = (long) value;
2599 /* Create an array-class if necessary. */
2601 if (class_is_primitive(c)) {
2602 ac = Primitive::get_arrayclass_by_name(c->name);
2604 // Arrays of void are not allowed.
2606 exceptions_throw_illegalargumentexception();
2611 ac = class_multiarray_of((length - 1), ac, true);
2614 ac = class_multiarray_of(length, c, true);
2619 /* Allocate a new array on the heap. */
2621 a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
2627 /* JVM_InitializeSocketLibrary */
2629 jint JVM_InitializeSocketLibrary()
2631 TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
2633 HPI& hpi = VM::get_current()->get_hpi();
2634 return hpi.initialize_socket_library();
2640 jint JVM_Socket(jint domain, jint type, jint protocol)
2642 TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
2644 return os::socket(domain, type, protocol);
2648 /* JVM_SocketClose */
2650 jint JVM_SocketClose(jint fd)
2652 TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
2654 return os::close(fd);
2658 /* JVM_SocketShutdown */
2660 jint JVM_SocketShutdown(jint fd, jint howto)
2662 TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
2664 return os::shutdown(fd, howto);
2670 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2672 log_println("JVM_Recv: IMPLEMENT ME!");
2680 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2682 TRACEJVMCALLSENTER(("JVM_Send(fd=%d, buf=%p, nBytes=%d, flags=%d", fd, buf, nBytes, flags));
2684 int result = os::send(fd, buf, nBytes, flags);
2686 TRACEJVMCALLSEXIT(("->%d", result));
2694 jint JVM_Timeout(int fd, long timeout)
2696 log_println("JVM_Timeout: IMPLEMENT ME!");
2704 jint JVM_Listen(jint fd, jint count)
2706 TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
2708 return os::listen(fd, count);
2714 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2716 TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
2718 return os::connect(fd, him, len);
2724 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2726 log_println("JVM_Bind: IMPLEMENT ME!");
2734 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2736 TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
2738 return os::accept(fd, him, (socklen_t *) len);
2744 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2746 log_println("JVM_RecvFrom: IMPLEMENT ME!");
2752 /* JVM_GetSockName */
2754 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2756 TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
2758 return os::getsockname(fd, him, (socklen_t *) len);
2764 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2766 log_println("JVM_SendTo: IMPLEMENT ME!");
2772 /* JVM_SocketAvailable */
2774 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2776 #if defined(FIONREAD)
2780 TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
2784 result = ioctl(fd, FIONREAD, &bytes);
2793 # error FIONREAD not defined
2798 /* JVM_GetSockOpt */
2800 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2802 TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
2804 return os::getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
2808 /* JVM_SetSockOpt */
2810 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2812 TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
2814 return os::setsockopt(fd, level, optname, optval, optlen);
2818 /* JVM_GetHostName */
2820 int JVM_GetHostName(char *name, int namelen)
2824 TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
2826 result = os::gethostname(name, namelen);
2828 TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
2834 /* JVM_GetHostByAddr */
2836 struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
2838 log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2844 /* JVM_GetHostByName */
2846 struct hostent *JVM_GetHostByName(char* name)
2848 log_println("JVM_GetHostByName: IMPLEMENT ME!");
2854 /* JVM_GetProtoByName */
2856 struct protoent *JVM_GetProtoByName(char* name)
2858 log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2864 /* JVM_LoadLibrary */
2866 void* JVM_LoadLibrary(const char* name)
2868 TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
2870 utf* u = utf_new_char(name);
2872 NativeLibrary nl(u);
2873 void* handle = nl.open();
2875 TRACEJVMCALLSEXIT(("->%p", handle));
2881 /* JVM_UnloadLibrary */
2883 void JVM_UnloadLibrary(void* handle)
2885 TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
2887 NativeLibrary nl(handle);
2892 /* JVM_FindLibraryEntry */
2894 void *JVM_FindLibraryEntry(void* handle, const char* name)
2898 TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
2900 HPI& hpi = VM::get_current()->get_hpi();
2901 symbol = hpi.get_library().FindLibraryEntry(handle, name);
2903 TRACEJVMCALLSEXIT(("->%p", symbol));
2911 jboolean JVM_IsNaN(jdouble d)
2915 TRACEJVMCALLSENTER(("JVM_IsNaN(d=%f)", d));
2919 TRACEJVMCALLSEXIT(("->%d", result));
2925 /* JVM_IsSupportedJNIVersion */
2927 jboolean JVM_IsSupportedJNIVersion(jint version)
2929 TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
2931 return jni_version_check(version);
2935 /* JVM_InternString */
2937 jstring JVM_InternString(JNIEnv *env, jstring str)
2939 TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
2941 return (jstring) javastring_intern((java_handle_t *) str);
2945 /* JVM_RawMonitorCreate */
2947 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
2949 TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
2951 Mutex* m = new Mutex();
2957 /* JVM_RawMonitorDestroy */
2959 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void* mon)
2961 TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
2963 delete ((Mutex*) mon);
2967 /* JVM_RawMonitorEnter */
2969 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void* mon)
2971 TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
2973 ((Mutex*) mon)->lock();
2979 /* JVM_RawMonitorExit */
2981 JNIEXPORT void JNICALL JVM_RawMonitorExit(void* mon)
2983 TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
2985 ((Mutex*) mon)->unlock();
2989 /* JVM_SetPrimitiveFieldValues */
2991 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
2993 log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
2997 /* JVM_GetPrimitiveFieldValues */
2999 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3001 log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
3005 /* JVM_AccessVMBooleanFlag */
3007 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
3009 log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
3015 /* JVM_AccessVMIntFlag */
3017 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
3019 log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
3025 /* JVM_VMBreakPoint */
3027 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
3029 log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
3033 /* JVM_GetClassFields */
3035 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
3037 log_println("JVM_GetClassFields: IMPLEMENT ME!");
3043 /* JVM_GetClassMethods */
3045 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
3047 log_println("JVM_GetClassMethods: IMPLEMENT ME!");
3053 /* JVM_GetClassConstructors */
3055 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
3057 log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
3063 /* JVM_GetClassField */
3065 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
3067 log_println("JVM_GetClassField: IMPLEMENT ME!");
3073 /* JVM_GetClassMethod */
3075 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
3077 log_println("JVM_GetClassMethod: IMPLEMENT ME!");
3083 /* JVM_GetClassConstructor */
3085 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
3087 log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
3093 /* JVM_NewInstance */
3095 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
3097 log_println("JVM_NewInstance: IMPLEMENT ME!");
3105 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
3107 log_println("JVM_GetField: IMPLEMENT ME!");
3113 /* JVM_GetPrimitiveField */
3115 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
3119 log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
3129 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
3131 log_println("JVM_SetField: IMPLEMENT ME!");
3135 /* JVM_SetPrimitiveField */
3137 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
3139 log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
3143 /* JVM_InvokeMethod */
3145 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
3147 TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
3149 java_lang_reflect_Method jlrm(method);
3151 java_handle_t* result = jlrm.invoke((java_handle_t*) obj, (java_handle_objectarray_t*) args0);
3153 return (jobject) result;
3157 /* JVM_NewInstanceFromConstructor */
3159 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
3161 TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
3163 java_lang_reflect_Constructor jlrc(con);
3164 java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args0);
3170 /* JVM_SupportsCX8 */
3172 jboolean JVM_SupportsCX8()
3174 TRACEJVMCALLS(("JVM_SupportsCX8()"));
3184 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
3186 log_println("JVM_CX8Field: IMPLEMENT ME!");
3192 /* JVM_GetAllThreads */
3194 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
3196 // Get a list of all active threads.
3197 list<threadobject*> active_threads;
3198 ThreadList::get_active_threads(active_threads);
3200 // Allocate array to hold the java.lang.Thread objects.
3201 int32_t length = active_threads.size();
3202 java_handle_objectarray_t* oa = builtin_anewarray(length, class_java_lang_Thread);
3207 // Iterate over all threads (which were active just a second ago).
3209 for (List<threadobject*>::iterator it = active_threads.begin(); it != active_threads.end(); it++) {
3210 threadobject* t = *it;
3212 java_handle_t* h = thread_get_object(t);
3215 array_objectarray_element_set(oa, index, h);
3224 /* JVM_DumpThreads */
3226 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
3230 TRACEJVMCALLS(("JVM_DumpThreads((env=%p, threadClass=%p, threads=%p)", env, threadClass, threads));
3232 if (threads == NULL) {
3233 exceptions_throw_nullpointerexception();
3237 // Get length of the threads array.
3238 int32_t length = array_length_get((java_handle_t*) threads);
3241 exceptions_throw_illegalargumentexception();
3245 // Allocate array to hold stacktraces.
3246 classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
3247 java_handle_objectarray_t* oas = builtin_anewarray(length, arrayclass);
3253 // Iterate over all passed thread objects.
3254 for (i = 0; i < length; i++) {
3255 java_handle_t* thread = array_objectarray_element_get(threads, i);
3257 // Get thread for the given thread object.
3258 threadobject* t = thread_get_thread(thread);
3263 // Get stacktrace for given thread.
3264 stacktrace_t* st = stacktrace_get_of_thread(t);
3266 // Convert stacktrace into array of StackTraceElements.
3267 java_handle_objectarray_t* oa = stacktrace_get_StackTraceElements(st);
3272 array_objectarray_element_set(oas, i, (java_handle_t*) oa);
3279 /* JVM_GetManagement */
3281 void *JVM_GetManagement(jint version)
3283 TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
3285 return Management::get_jmm_interface(version);
3289 /* JVM_InitAgentProperties */
3291 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
3293 log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
3299 /* JVM_GetEnclosingMethodInfo */
3301 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
3305 java_handle_objectarray_t *oa;
3307 TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
3309 c = LLNI_classinfo_unwrap(ofClass);
3311 if ((c == NULL) || class_is_primitive(c))
3314 m = class_get_enclosingmethod_raw(c);
3319 oa = builtin_anewarray(3, class_java_lang_Object);
3324 array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
3325 array_objectarray_element_set(oa, 1, javastring_new(m->name));
3326 array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
3328 return (jobjectArray) oa;
3332 /* JVM_GetThreadStateValues */
3334 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
3336 java_handle_intarray_t *ia;
3338 TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
3339 env, javaThreadState));
3341 /* If new thread states are added in future JDK and VM versions,
3342 this should check if the JDK version is compatible with thread
3343 states supported by the VM. Return NULL if not compatible.
3345 This function must map the VM java_lang_Thread::ThreadStatus
3346 to the Java thread state that the JDK supports. */
3348 switch (javaThreadState) {
3349 case THREAD_STATE_NEW:
3350 ia = builtin_newarray_int(1);
3355 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
3358 case THREAD_STATE_RUNNABLE:
3359 ia = builtin_newarray_int(1);
3364 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
3367 case THREAD_STATE_BLOCKED:
3368 ia = builtin_newarray_int(1);
3373 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
3376 case THREAD_STATE_WAITING:
3377 ia = builtin_newarray_int(2);
3382 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
3383 array_intarray_element_set(ia, 1, THREAD_STATE_PARKED);
3386 case THREAD_STATE_TIMED_WAITING:
3387 ia = builtin_newarray_int(2);
3392 /* XXX Not sure about that one. */
3393 /* array_intarray_element_set(ia, 0, SLEEPING); */
3394 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
3395 array_intarray_element_set(ia, 1, THREAD_STATE_TIMED_PARKED);
3398 case THREAD_STATE_TERMINATED:
3399 ia = builtin_newarray_int(1);
3404 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
3408 /* Unknown state - probably incompatible JDK version */
3412 return (jintArray) ia;
3416 /* JVM_GetThreadStateNames */
3418 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
3420 java_handle_intarray_t *ia;
3421 java_handle_objectarray_t *oa;
3424 TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
3425 env, javaThreadState, values));
3427 ia = (java_handle_intarray_t *) values;
3429 /* If new thread states are added in future JDK and VM versions,
3430 this should check if the JDK version is compatible with thread
3431 states supported by the VM. Return NULL if not compatible.
3433 This function must map the VM java_lang_Thread::ThreadStatus
3434 to the Java thread state that the JDK supports. */
3436 if (values == NULL) {
3437 exceptions_throw_nullpointerexception();
3441 switch (javaThreadState) {
3442 case THREAD_STATE_NEW:
3443 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
3445 oa = builtin_anewarray(1, class_java_lang_String);
3450 s = javastring_new(utf_new_char("NEW"));
3455 array_objectarray_element_set(oa, 0, s);
3458 case THREAD_STATE_RUNNABLE:
3459 oa = builtin_anewarray(1, class_java_lang_String);
3464 s = javastring_new(utf_new_char("RUNNABLE"));
3469 array_objectarray_element_set(oa, 0, s);
3472 case THREAD_STATE_BLOCKED:
3473 oa = builtin_anewarray(1, class_java_lang_String);
3478 s = javastring_new(utf_new_char("BLOCKED"));
3483 array_objectarray_element_set(oa, 0, s);
3486 case THREAD_STATE_WAITING:
3487 oa = builtin_anewarray(2, class_java_lang_String);
3492 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
3497 array_objectarray_element_set(oa, 0, s);
3499 s = javastring_new(utf_new_char("WAITING.PARKED"));
3504 array_objectarray_element_set(oa, 1, s);
3507 case THREAD_STATE_TIMED_WAITING:
3508 oa = builtin_anewarray(2, class_java_lang_String);
3513 /* s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
3514 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
3519 array_objectarray_element_set(oa, 0, s);
3521 s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
3526 array_objectarray_element_set(oa, 1, s);
3529 case THREAD_STATE_TERMINATED:
3530 oa = builtin_anewarray(1, class_java_lang_String);
3535 s = javastring_new(utf_new_char("TERMINATED"));
3540 array_objectarray_element_set(oa, 0, s);
3544 /* Unknown state - probably incompatible JDK version */
3548 return (jobjectArray) oa;
3552 /* JVM_GetVersionInfo */
3554 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3556 log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3560 /* OS: JVM_RegisterSignal */
3562 void *JVM_RegisterSignal(jint sig, void *handler)
3564 functionptr newHandler;
3566 TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
3568 if (handler == (void *) 2)
3569 newHandler = (functionptr) signal_thread_handler;
3571 newHandler = (functionptr) (uintptr_t) handler;
3578 /* These signals are already used by the VM. */
3582 /* This signal is used by the VM to dump thread stacks unless
3583 ReduceSignalUsage is set, in which case the user is allowed
3584 to set his own _native_ handler for this signal; thus, in
3585 either case, we do not allow JVM_RegisterSignal to change
3595 signal_register_signal(sig, newHandler, SA_RESTART | SA_SIGINFO);
3597 /* XXX Should return old handler. */
3603 /* OS: JVM_RaiseSignal */
3605 jboolean JVM_RaiseSignal(jint sig)
3607 log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3613 /* OS: JVM_FindSignal */
3615 jint JVM_FindSignal(const char *name)
3617 TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
3619 #if defined(__LINUX__)
3620 if (strcmp(name, "HUP") == 0)
3623 if (strcmp(name, "INT") == 0)
3626 if (strcmp(name, "TERM") == 0)
3628 #elif defined(__SOLARIS__)
3631 if (os::str2sig(name, &signum) == -1)
3636 # error Not implemented for this OS.
3646 * These are local overrides for various environment variables in Emacs.
3647 * Please do not remove this and leave it at the end of the file, where
3648 * Emacs will automagically detect them.
3649 * ---------------------------------------------------------------------
3652 * indent-tabs-mode: t
3656 * vim:noexpandtab:sw=4:ts=4: