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"
68 #include "toolbox/logging.hpp"
69 #include "toolbox/list.hpp"
71 #include "vm/array.hpp"
73 #if defined(ENABLE_ASSERTION)
74 #include "vm/assertion.hpp"
77 #include "vm/jit/builtin.hpp"
78 #include "vm/classcache.hpp"
79 #include "vm/exceptions.hpp"
80 #include "vm/global.h"
81 #include "vm/globals.hpp"
82 #include "vm/initialize.hpp"
83 #include "vm/javaobjects.hpp"
84 #include "vm/options.h"
86 #include "vm/package.hpp"
87 #include "vm/primitive.hpp"
88 #include "vm/properties.hpp"
89 #include "vm/resolve.hpp"
90 #include "vm/signallocal.hpp"
91 #include "vm/string.hpp"
94 #include "vm/jit/stacktrace.hpp"
97 /* debugging macros ***********************************************************/
101 # define TRACEJVMCALLS(x) \
103 if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) { \
108 # define TRACEJVMCALLSENTER(x) \
110 if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) { \
116 # define TRACEJVMCALLSEXIT(x) \
118 if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) { \
124 # define TRACEJVMCALLSVERBOSE(x) \
126 if (opt_TraceJVMCallsVerbose) { \
131 # define PRINTJVMWARNINGS(x)
133 /* if (opt_PrintJVMWarnings) { \ */
134 /* log_println x; \ */
140 # define TRACEJVMCALLS(x)
141 # define TRACEJVMCALLSENTER(x)
142 # define TRACEJVMCALLSEXIT(x)
143 # define TRACEJVMCALLSVERBOSE(x)
144 # define PRINTJVMWARNINGS(x)
149 // Interface functions are exported as C functions.
152 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
154 if ((intptr_t) count <= 0)
157 return vsnprintf(str, count, fmt, args);
161 int jio_snprintf(char *str, size_t count, const char *fmt, ...)
167 len = jio_vsnprintf(str, count, fmt, ap);
174 int jio_fprintf(FILE* f, const char *fmt, ...)
176 log_println("jio_fprintf: IMPLEMENT ME!");
182 int jio_vfprintf(FILE* f, const char *fmt, va_list args)
184 log_println("jio_vfprintf: IMPLEMENT ME!");
190 int jio_printf(const char *fmt, ...)
192 log_println("jio_printf: IMPLEMENT ME!");
198 /* JVM_GetInterfaceVersion */
200 jint JVM_GetInterfaceVersion()
202 /* This is defined in hotspot/src/share/vm/prims/jvm.h */
204 #define JVM_INTERFACE_VERSION 4
206 return JVM_INTERFACE_VERSION;
210 /* JVM_CurrentTimeMillis */
212 jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
214 TRACEJVMCALLS(("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored));
216 return (jlong) builtin_currenttimemillis();
222 jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
224 TRACEJVMCALLS(("JVM_NanoTime(env=%p, ignored=%p)", env, ignored));
226 return (jlong) builtin_nanotime();
232 void JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length)
237 s = (java_handle_t *) src;
238 d = (java_handle_t *) dst;
240 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));
242 builtin_arraycopy(s, src_pos, d, dst_pos, length);
246 /* JVM_InitProperties */
248 jobject JVM_InitProperties(JNIEnv *env, jobject properties)
253 TRACEJVMCALLS(("JVM_InitProperties(env=%p, properties=%p)", env, properties));
255 h = (java_handle_t *) properties;
257 /* Convert the -XX:MaxDirectMemorySize= command line flag to the
258 sun.nio.MaxDirectMemorySize property. Do this after setting
259 user properties to prevent people from setting the value with a
260 -D option, as requested. */
262 jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
263 VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
265 // Fill the java.util.Properties object.
266 VM::get_current()->get_properties().fill(h);
274 void JVM_Exit(jint code)
276 log_println("JVM_Exit: IMPLEMENT ME!");
282 void JVM_Halt(jint code)
284 TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
291 /* JVM_OnExit(void (*func)) */
293 void JVM_OnExit(void (*func)(void))
295 log_println("JVM_OnExit(void (*func): IMPLEMENT ME!");
303 TRACEJVMCALLS(("JVM_GC()"));
309 /* JVM_MaxObjectInspectionAge */
311 jlong JVM_MaxObjectInspectionAge(void)
313 log_println("JVM_MaxObjectInspectionAge: IMPLEMENT ME!");
319 /* JVM_TraceInstructions */
321 void JVM_TraceInstructions(jboolean on)
323 log_println("JVM_TraceInstructions: IMPLEMENT ME!");
327 /* JVM_TraceMethodCalls */
329 void JVM_TraceMethodCalls(jboolean on)
331 log_println("JVM_TraceMethodCalls: IMPLEMENT ME!");
335 /* JVM_TotalMemory */
337 jlong JVM_TotalMemory(void)
339 TRACEJVMCALLS(("JVM_TotalMemory()"));
341 return gc_get_heap_size();
347 jlong JVM_FreeMemory(void)
349 TRACEJVMCALLS(("JVM_FreeMemory()"));
351 return gc_get_free_bytes();
357 jlong JVM_MaxMemory(void)
359 TRACEJVMCALLS(("JVM_MaxMemory()"));
361 return gc_get_max_heap_size();
365 /* JVM_ActiveProcessorCount */
367 jint JVM_ActiveProcessorCount(void)
369 TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
371 return os::processors_online();
375 /* JVM_FillInStackTrace */
377 void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
379 TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
381 java_handle_bytearray_t* ba = stacktrace_get_current();
386 java_lang_Throwable jlt(receiver, ba);
390 /* JVM_PrintStackTrace */
392 void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
394 log_println("JVM_PrintStackTrace: IMPLEMENT ME!");
398 /* JVM_GetStackTraceDepth */
400 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
402 TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
404 java_lang_Throwable jlt(throwable);
407 exceptions_throw_nullpointerexception();
411 java_handle_bytearray_t* ba = jlt.get_backtrace();
416 // We need a critical section here as the stacktrace structure is
417 // mapped onto a Java byte-array.
421 stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
423 int32_t depth = st->length;
431 /* JVM_GetStackTraceElement */
433 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
435 TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
437 java_lang_Throwable jlt(throwable);
438 java_handle_bytearray_t* ba = jlt.get_backtrace();
440 // XXX We need a critical section here as the stacktrace structure is
441 // mapped onto a Java byte-array.
442 stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
444 return stacktrace_get_StackTraceElement(st, index);
450 jint JVM_IHashCode(JNIEnv* env, jobject handle)
452 TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
454 java_lang_Object o(handle);
456 return o.get_hashcode();
460 /* JVM_MonitorWait */
462 void JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)
464 #if defined(ENABLE_THREADS)
468 TRACEJVMCALLS(("JVM_MonitorWait(env=%p, handle=%p, ms=%ld)", env, handle, ms));
470 /* exceptions_throw_illegalargumentexception("argument out of range"); */
471 exceptions_throw_illegalargumentexception();
475 #if defined(ENABLE_THREADS)
476 o = (java_handle_t *) handle;
478 lock_wait_for_object(o, ms, 0);
483 /* JVM_MonitorNotify */
485 void JVM_MonitorNotify(JNIEnv* env, jobject handle)
487 #if defined(ENABLE_THREADS)
491 TRACEJVMCALLS(("JVM_MonitorNotify(env=%p, handle=%p)", env, handle));
493 #if defined(ENABLE_THREADS)
494 o = (java_handle_t *) handle;
496 lock_notify_object(o);
501 /* JVM_MonitorNotifyAll */
503 void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
505 #if defined(ENABLE_THREADS)
509 TRACEJVMCALLS(("JVM_MonitorNotifyAll(env=%p, handle=%p)", env, handle));
511 #if defined(ENABLE_THREADS)
512 o = (java_handle_t *) handle;
514 lock_notify_all_object(o);
521 jobject JVM_Clone(JNIEnv* env, jobject handle)
523 TRACEJVMCALLS(("JVM_Clone(env=%p, handle=%p)", env, handle));
525 return (jobject) builtin_clone(env, (java_handle_t *) handle);
529 /* JVM_InitializeCompiler */
531 void JVM_InitializeCompiler (JNIEnv *env, jclass compCls)
533 log_println("JVM_InitializeCompiler : IMPLEMENT ME!");
537 /* JVM_IsSilentCompiler */
539 jboolean JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)
541 log_println("JVM_IsSilentCompiler: IMPLEMENT ME!");
547 /* JVM_CompileClass */
549 jboolean JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)
551 log_println("JVM_CompileClass: IMPLEMENT ME!");
557 /* JVM_CompileClasses */
559 jboolean JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)
561 log_println("JVM_CompileClasses: IMPLEMENT ME!");
567 /* JVM_CompilerCommand */
569 jobject JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)
571 log_println("JVM_CompilerCommand: IMPLEMENT ME!");
577 /* JVM_EnableCompiler */
579 void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
581 TRACEJVMCALLS(("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls));
582 PRINTJVMWARNINGS(("JVM_EnableCompiler not supported"));
586 /* JVM_DisableCompiler */
588 void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
590 TRACEJVMCALLS(("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls));
591 PRINTJVMWARNINGS(("JVM_DisableCompiler not supported"));
595 /* JVM_GetLastErrorString */
597 jint JVM_GetLastErrorString(char* buf, int len)
599 TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
601 HPI& hpi = VM::get_current()->get_hpi();
602 return hpi.get_system().GetLastErrorString(buf, len);
608 char *JVM_NativePath(char* path)
610 TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
612 HPI& hpi = VM::get_current()->get_hpi();
613 return hpi.get_file().NativePath(path);
617 /* JVM_GetCallerClass */
619 jclass JVM_GetCallerClass(JNIEnv* env, int depth)
623 TRACEJVMCALLS(("JVM_GetCallerClass(env=%p, depth=%d)", env, depth));
625 c = stacktrace_get_caller_class(depth);
631 /* JVM_FindPrimitiveClass */
633 jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
638 TRACEJVMCALLS(("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s));
641 c = Primitive::get_class_by_name(u);
643 return (jclass) LLNI_classinfo_wrap(c);
647 /* JVM_ResolveClass */
649 void JVM_ResolveClass(JNIEnv* env, jclass cls)
651 TRACEJVMCALLS(("JVM_ResolveClass(env=%p, cls=%p)", env, cls));
652 PRINTJVMWARNINGS(("JVM_ResolveClass not implemented"));
656 /* JVM_FindClassFromClassLoader */
658 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
664 TRACEJVMCALLS(("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError));
666 /* As of now, OpenJDK does not call this function with throwError
669 assert(throwError == false);
671 u = utf_new_char(name);
672 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
674 c = load_class_from_classloader(u, cl);
680 if (!(c->state & CLASS_INITIALIZED))
681 if (!initialize_class(c))
684 return (jclass) LLNI_classinfo_wrap(c);
688 /* JVM_FindClassFromClass */
690 jclass JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, jclass from)
692 log_println("JVM_FindClassFromClass: IMPLEMENT ME!");
698 /* JVM_DefineClass */
700 jclass JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)
702 log_println("JVM_DefineClass: IMPLEMENT ME!");
708 /* JVM_DefineClassWithSource */
710 jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)
716 TRACEJVMCALLS(("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source));
719 u = utf_new_char(name);
723 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
725 /* XXX do something with source */
727 c = class_define(u, cl, len, (uint8_t *) buf, (java_handle_t *) pd);
729 return (jclass) LLNI_classinfo_wrap(c);
733 /* JVM_FindLoadedClass */
735 jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
741 TRACEJVMCALLS(("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name));
743 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
745 u = javastring_toutf((java_handle_t *) name, true);
746 c = classcache_lookup(cl, u);
748 return (jclass) LLNI_classinfo_wrap(c);
752 /* JVM_GetClassName */
754 jstring JVM_GetClassName(JNIEnv *env, jclass cls)
758 TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
760 c = LLNI_classinfo_unwrap(cls);
762 return (jstring) class_get_classname(c);
766 /* JVM_GetClassInterfaces */
768 jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
771 java_handle_objectarray_t *oa;
773 TRACEJVMCALLS(("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls));
775 c = LLNI_classinfo_unwrap(cls);
777 oa = class_get_interfaces(c);
779 return (jobjectArray) oa;
783 /* JVM_GetClassLoader */
785 jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
790 TRACEJVMCALLSENTER(("JVM_GetClassLoader(env=%p, cls=%p)", env, cls));
792 c = LLNI_classinfo_unwrap(cls);
793 cl = class_get_classloader(c);
795 TRACEJVMCALLSEXIT(("->%p", cl));
801 /* JVM_IsInterface */
803 jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
807 TRACEJVMCALLS(("JVM_IsInterface(env=%p, cls=%p)", env, cls));
809 c = LLNI_classinfo_unwrap(cls);
811 return class_is_interface(c);
815 /* JVM_GetClassSigners */
817 jobjectArray JVM_GetClassSigners(JNIEnv *env, jclass cls)
819 log_println("JVM_GetClassSigners: IMPLEMENT ME!");
825 /* JVM_SetClassSigners */
827 void JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)
830 java_handle_objectarray_t *hoa;
832 TRACEJVMCALLS(("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers));
834 c = LLNI_classinfo_unwrap(cls);
836 hoa = (java_handle_objectarray_t *) signers;
838 /* This call is ignored for primitive types and arrays. Signers
839 are only set once, ClassLoader.java, and thus shouldn't be
840 called with an array. Only the bootstrap loader creates
843 if (class_is_primitive(c) || class_is_array(c))
846 LLNI_classinfo_field_set(c, signers, hoa);
850 /* JVM_GetProtectionDomain */
852 jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
856 TRACEJVMCALLS(("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls));
858 c = LLNI_classinfo_unwrap(cls);
861 exceptions_throw_nullpointerexception();
865 /* Primitive types do not have a protection domain. */
867 if (class_is_primitive(c))
870 return (jobject) c->protectiondomain;
874 /* JVM_SetProtectionDomain */
876 void JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain)
878 log_println("JVM_SetProtectionDomain: IMPLEMENT ME!");
882 /* JVM_DoPrivileged */
884 jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
889 java_handle_t *result;
892 TRACEJVMCALLS(("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException));
894 h = (java_handle_t *) action;
895 LLNI_class_get(h, c);
897 if (action == NULL) {
898 exceptions_throw_nullpointerexception();
902 /* lookup run() method (throw no exceptions) */
904 m = class_resolveclassmethod(c, utf_run, utf_void__java_lang_Object, c,
907 if ((m == NULL) || !(m->flags & ACC_PUBLIC) || (m->flags & ACC_STATIC)) {
908 exceptions_throw_internalerror("No run method");
912 /* XXX It seems something with a privileged stack needs to be done
915 result = vm_call_method(m, h);
917 e = exceptions_get_exception();
920 if ( builtin_instanceof(e, class_java_lang_Exception) &&
921 !builtin_instanceof(e, class_java_lang_RuntimeException)) {
922 exceptions_clear_exception();
923 exceptions_throw_privilegedactionexception(e);
929 return (jobject) result;
933 /* JVM_GetInheritedAccessControlContext */
935 jobject JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)
937 log_println("JVM_GetInheritedAccessControlContext: IMPLEMENT ME!");
943 /* JVM_GetStackAccessControlContext */
945 jobject JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)
947 TRACEJVMCALLS(("JVM_GetStackAccessControlContext(env=%p, cls=%p): IMPLEMENT ME!", env, cls));
949 /* XXX All stuff I tested so far works without that function. At
950 some point we have to implement it, but I disable the output
951 for now to make IcedTea happy. */
957 /* JVM_IsArrayClass */
959 jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
963 TRACEJVMCALLS(("JVM_IsArrayClass(env=%p, cls=%p)", env, cls));
965 c = LLNI_classinfo_unwrap(cls);
967 return class_is_array(c);
971 /* JVM_IsPrimitiveClass */
973 jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
977 TRACEJVMCALLS(("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls));
979 c = LLNI_classinfo_unwrap(cls);
981 return class_is_primitive(c);
985 /* JVM_GetComponentType */
987 jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
989 classinfo *component;
992 TRACEJVMCALLS(("JVM_GetComponentType(env=%p, cls=%p)", env, cls));
994 c = LLNI_classinfo_unwrap(cls);
996 component = class_get_componenttype(c);
998 return (jclass) LLNI_classinfo_wrap(component);
1002 /* JVM_GetClassModifiers */
1004 jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
1009 TRACEJVMCALLS(("JVM_GetClassModifiers(env=%p, cls=%p)", env, cls));
1011 c = LLNI_classinfo_unwrap(cls);
1013 flags = class_get_modifiers(c, false);
1019 /* JVM_GetDeclaredClasses */
1021 jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
1024 java_handle_objectarray_t *oa;
1026 TRACEJVMCALLS(("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass));
1028 c = LLNI_classinfo_unwrap(ofClass);
1030 oa = class_get_declaredclasses(c, false);
1032 return (jobjectArray) oa;
1036 /* JVM_GetDeclaringClass */
1038 jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
1043 TRACEJVMCALLS(("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass));
1045 c = LLNI_classinfo_unwrap(ofClass);
1047 dc = class_get_declaringclass(c);
1049 return (jclass) LLNI_classinfo_wrap(dc);
1053 /* JVM_GetClassSignature */
1055 jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
1061 TRACEJVMCALLS(("JVM_GetClassSignature(env=%p, cls=%p)", env, cls));
1063 c = LLNI_classinfo_unwrap(cls);
1065 /* Get the signature of the class. */
1067 u = class_get_signature(c);
1072 /* Convert UTF-string to a Java-string. */
1074 s = javastring_new(u);
1080 /* JVM_GetClassAnnotations */
1082 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
1084 TRACEJVMCALLS(("JVM_GetClassAnnotations(env=%p, cls=%p)", env, cls));
1087 exceptions_throw_nullpointerexception();
1091 classinfo* c = LLNI_classinfo_unwrap(cls);
1093 /* get annotations: */
1094 java_handle_bytearray_t* annotations = class_get_annotations(c);
1096 return (jbyteArray) annotations;
1100 /* JVM_GetFieldAnnotations */
1102 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
1104 TRACEJVMCALLS(("JVM_GetFieldAnnotations(env=%p, field=%p)", env, field));
1106 java_lang_reflect_Field jlrf(field);
1108 if (jlrf.is_null()) {
1109 exceptions_throw_nullpointerexception();
1113 return (jbyteArray) jlrf.get_annotations();
1117 /* JVM_GetMethodAnnotations */
1119 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
1121 TRACEJVMCALLS(("JVM_GetMethodAnnotations(env=%p, method=%p)", env, method));
1123 java_lang_reflect_Method jlrm(method);
1125 if (jlrm.is_null()) {
1126 exceptions_throw_nullpointerexception();
1130 return (jbyteArray) jlrm.get_annotations();
1134 /* JVM_GetMethodDefaultAnnotationValue */
1136 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
1138 TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue(env=%p, method=%p)", env, method));
1140 java_lang_reflect_Method jlrm(method);
1142 if (jlrm.is_null()) {
1143 exceptions_throw_nullpointerexception();
1147 return (jbyteArray) jlrm.get_annotationDefault();
1151 /* JVM_GetMethodParameterAnnotations */
1153 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
1155 TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations(env=%p, method=%p)", env, method));
1157 java_lang_reflect_Method jlrm(method);
1159 if (jlrm.is_null()) {
1160 exceptions_throw_nullpointerexception();
1164 return (jbyteArray) jlrm.get_parameterAnnotations();
1168 /* JVM_GetClassDeclaredFields */
1170 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1173 java_handle_objectarray_t *oa;
1175 TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1177 c = LLNI_classinfo_unwrap(ofClass);
1179 oa = class_get_declaredfields(c, publicOnly);
1181 return (jobjectArray) oa;
1185 /* JVM_GetClassDeclaredMethods */
1187 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1189 TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1191 classinfo* c = LLNI_classinfo_unwrap(ofClass);
1193 java_handle_objectarray_t* oa = class_get_declaredmethods(c, publicOnly);
1195 return (jobjectArray) oa;
1199 /* JVM_GetClassDeclaredConstructors */
1201 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1204 java_handle_objectarray_t *oa;
1206 TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1208 c = LLNI_classinfo_unwrap(ofClass);
1210 oa = class_get_declaredconstructors(c, publicOnly);
1212 return (jobjectArray) oa;
1216 /* JVM_GetClassAccessFlags */
1218 jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
1222 TRACEJVMCALLS(("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls));
1224 c = LLNI_classinfo_unwrap(cls);
1226 /* Primitive type classes have the correct access flags. */
1228 return c->flags & ACC_CLASS_REFLECT_MASK;
1232 /* JVM_GetClassConstantPool */
1234 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
1236 #if defined(ENABLE_ANNOTATIONS)
1237 TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
1239 java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
1240 sun_reflect_ConstantPool cp(h, cls);
1246 return (jobject) cp.get_handle();
1248 log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
1254 /* JVM_ConstantPoolGetSize */
1256 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
1258 classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1260 TRACEJVMCALLS(("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool));
1262 c = LLNI_classinfo_unwrap(jcpool);
1268 /* JVM_ConstantPoolGetClassAt */
1270 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1272 constant_classref *ref; /* classref to the class at constant pool index 'index' */
1273 classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1274 classinfo *result; /* classinfo of the class at constant pool index 'index' */
1276 TRACEJVMCALLS(("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index));
1278 c = LLNI_classinfo_unwrap(jcpool);
1280 ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1283 exceptions_throw_illegalargumentexception();
1287 result = resolve_classref_eager(ref);
1289 return (jclass) LLNI_classinfo_wrap(result);
1293 /* JVM_ConstantPoolGetClassAtIfLoaded */
1295 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1297 constant_classref *ref; /* classref to the class at constant pool index 'index' */
1298 classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1299 classinfo *result; /* classinfo of the class at constant pool index 'index' */
1301 TRACEJVMCALLS(("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index));
1303 c = LLNI_classinfo_unwrap(jcpool);
1305 ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1308 exceptions_throw_illegalargumentexception();
1312 if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result)) {
1316 if ((result == NULL) || !(result->state & CLASS_LOADED)) {
1320 return (jclass) LLNI_classinfo_wrap(result);
1324 /* JVM_ConstantPoolGetMethodAt */
1326 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1328 constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1329 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1331 TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index));
1333 cls = LLNI_classinfo_unwrap(jcpool);
1334 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1337 exceptions_throw_illegalargumentexception();
1341 // Create a new java.lang.reflect.Method Java object.
1342 /* XXX: is that right? or do I have to use resolve_method_*? */
1343 java_lang_reflect_Method jlrm(ref->p.method);
1345 return (jobject) jlrm.get_handle();
1349 /* JVM_ConstantPoolGetMethodAtIfLoaded */
1351 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1353 constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1354 classinfo *c = NULL; /* resolved declaring class of the method */
1355 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1357 TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1359 cls = LLNI_classinfo_unwrap(jcpool);
1360 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1363 exceptions_throw_illegalargumentexception();
1367 if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1371 if (c == NULL || !(c->state & CLASS_LOADED)) {
1375 // Create a new java.lang.reflect.Method Java object.
1376 java_lang_reflect_Method jlrm(ref->p.method);
1378 return (jobject) jlrm.get_handle();
1382 /* JVM_ConstantPoolGetFieldAt */
1384 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1386 constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1387 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1389 TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index));
1391 cls = LLNI_classinfo_unwrap(jcpool);
1392 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1395 exceptions_throw_illegalargumentexception();
1399 // Create a new java.lang.reflect.Field Java object.
1400 java_lang_reflect_Field jlrf(ref->p.field);
1402 return (jobject) jlrf.get_handle();
1406 /* JVM_ConstantPoolGetFieldAtIfLoaded */
1408 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1410 constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1411 classinfo *c; /* resolved declaring class for the field */
1412 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1414 TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1416 cls = LLNI_classinfo_unwrap(jcpool);
1417 ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1420 exceptions_throw_illegalargumentexception();
1424 if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1428 if (c == NULL || !(c->state & CLASS_LOADED)) {
1432 // Create a new java.lang.reflect.Field Java object.
1433 java_lang_reflect_Field jlrf(ref->p.field);
1435 return (jobject) jlrf.get_handle();
1439 /* JVM_ConstantPoolGetMemberRefInfoAt */
1441 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1443 log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
1445 /* TODO: implement. (this is yet unused be OpenJDK but, so very low priority) */
1451 /* JVM_ConstantPoolGetIntAt */
1453 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1455 constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
1456 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1458 TRACEJVMCALLS(("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index));
1460 cls = LLNI_classinfo_unwrap(jcpool);
1461 ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
1464 exceptions_throw_illegalargumentexception();
1472 /* JVM_ConstantPoolGetLongAt */
1474 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1476 constant_long *ref; /* reference to the long value in constant pool at index 'index' */
1477 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1479 TRACEJVMCALLS(("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index));
1481 cls = LLNI_classinfo_unwrap(jcpool);
1482 ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
1485 exceptions_throw_illegalargumentexception();
1493 /* JVM_ConstantPoolGetFloatAt */
1495 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1497 constant_float *ref; /* reference to the float value in constant pool at index 'index' */
1498 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1500 TRACEJVMCALLS(("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index));
1502 cls = LLNI_classinfo_unwrap(jcpool);
1503 ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
1506 exceptions_throw_illegalargumentexception();
1514 /* JVM_ConstantPoolGetDoubleAt */
1516 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1518 constant_double *ref; /* reference to the double value in constant pool at index 'index' */
1519 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1521 TRACEJVMCALLS(("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index));
1523 cls = LLNI_classinfo_unwrap(jcpool);
1524 ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
1527 exceptions_throw_illegalargumentexception();
1535 /* JVM_ConstantPoolGetStringAt */
1537 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1539 utf *ref; /* utf object for the string in constant pool at index 'index' */
1540 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1542 TRACEJVMCALLS(("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index));
1544 cls = LLNI_classinfo_unwrap(jcpool);
1545 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
1548 exceptions_throw_illegalargumentexception();
1552 /* XXX: I hope literalstring_new is the right Function. */
1553 return (jstring)literalstring_new(ref);
1557 /* JVM_ConstantPoolGetUTF8At */
1559 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1561 utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
1562 classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1564 TRACEJVMCALLS(("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index));
1566 cls = LLNI_classinfo_unwrap(jcpool);
1567 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
1570 exceptions_throw_illegalargumentexception();
1574 /* XXX: I hope literalstring_new is the right Function. */
1575 return (jstring)literalstring_new(ref);
1579 /* JVM_DesiredAssertionStatus */
1581 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
1583 #if defined(ENABLE_ASSERTION)
1588 TRACEJVMCALLS(("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls));
1590 c = LLNI_classinfo_unwrap(cls);
1592 if (c->classloader == NULL) {
1593 status = (jboolean)assertion_system_enabled;
1596 status = (jboolean)assertion_user_enabled;
1599 if (list_assertion_names != NULL) {
1600 for (List<assertion_name_t*>::iterator it = list_assertion_names->begin();
1601 it != list_assertion_names->end(); it++) {
1602 assertion_name_t* item = *it;
1604 name = utf_new_char(item->name);
1605 if (name == c->packagename) {
1606 status = (jboolean)item->enabled;
1608 else if (name == c->name) {
1609 status = (jboolean)item->enabled;
1616 return (jboolean)false;
1621 /* JVM_AssertionStatusDirectives */
1623 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
1625 java_handle_objectarray_t *classes;
1626 java_handle_objectarray_t *packages;
1627 java_booleanarray_t *classEnabled;
1628 java_booleanarray_t *packageEnabled;
1629 #if defined(ENABLE_ASSERTION)
1634 TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
1636 #if defined(ENABLE_ASSERTION)
1637 classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
1639 classes = builtin_anewarray(0, class_java_lang_Object);
1641 if (classes == NULL)
1644 #if defined(ENABLE_ASSERTION)
1645 packages = builtin_anewarray(assertion_package_count, class_java_lang_Object);
1647 packages = builtin_anewarray(0, class_java_lang_Object);
1649 if (packages == NULL)
1652 #if defined(ENABLE_ASSERTION)
1653 classEnabled = builtin_newarray_boolean(assertion_class_count);
1655 classEnabled = builtin_newarray_boolean(0);
1657 if (classEnabled == NULL)
1660 #if defined(ENABLE_ASSERTION)
1661 packageEnabled = builtin_newarray_boolean(assertion_package_count);
1663 packageEnabled = builtin_newarray_boolean(0);
1665 if (packageEnabled == NULL)
1668 #if defined(ENABLE_ASSERTION)
1669 /* initialize arrays */
1671 if (list_assertion_names != NULL) {
1675 for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
1676 assertion_name_t* item = *it;
1678 js = javastring_new_from_ascii(item->name);
1683 if (item->package == false) {
1684 classes->data[i] = js;
1685 classEnabled->data[i] = (jboolean) item->enabled;
1689 packages->data[j] = js;
1690 packageEnabled->data[j] = (jboolean) item->enabled;
1697 /* set instance fields */
1699 java_lang_AssertionStatusDirectives jlasd(classes, classEnabled, packages, packageEnabled);
1701 return (jobject) jlasd.get_handle();
1705 /* JVM_GetClassNameUTF */
1707 const char *JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
1709 log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
1715 /* JVM_GetClassCPTypes */
1717 void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
1719 log_println("JVM_GetClassCPTypes: IMPLEMENT ME!");
1723 /* JVM_GetClassCPEntriesCount */
1725 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
1727 log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
1733 /* JVM_GetClassFieldsCount */
1735 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
1737 log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
1743 /* JVM_GetClassMethodsCount */
1745 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
1747 log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
1753 /* JVM_GetMethodIxExceptionIndexes */
1755 void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)
1757 log_println("JVM_GetMethodIxExceptionIndexes: IMPLEMENT ME!");
1761 /* JVM_GetMethodIxExceptionsCount */
1763 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
1765 log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
1771 /* JVM_GetMethodIxByteCode */
1773 void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)
1775 log_println("JVM_GetMethodIxByteCode: IMPLEMENT ME!");
1779 /* JVM_GetMethodIxByteCodeLength */
1781 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
1783 log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
1789 /* JVM_GetMethodIxExceptionTableEntry */
1791 void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)
1793 log_println("JVM_GetMethodIxExceptionTableEntry: IMPLEMENT ME!");
1797 /* JVM_GetMethodIxExceptionTableLength */
1799 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
1801 log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
1807 /* JVM_GetMethodIxModifiers */
1809 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
1811 log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
1817 /* JVM_GetFieldIxModifiers */
1819 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
1821 log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
1827 /* JVM_GetMethodIxLocalsCount */
1829 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
1831 log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
1837 /* JVM_GetMethodIxArgsSize */
1839 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
1841 log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
1847 /* JVM_GetMethodIxMaxStack */
1849 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
1851 log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
1857 /* JVM_IsConstructorIx */
1859 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
1861 log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
1867 /* JVM_GetMethodIxNameUTF */
1869 const char *JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
1871 log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
1877 /* JVM_GetMethodIxSignatureUTF */
1879 const char *JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
1881 log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
1887 /* JVM_GetCPFieldNameUTF */
1889 const char *JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1891 log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
1897 /* JVM_GetCPMethodNameUTF */
1899 const char *JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1901 log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
1907 /* JVM_GetCPMethodSignatureUTF */
1909 const char *JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1911 log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
1917 /* JVM_GetCPFieldSignatureUTF */
1919 const char *JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1921 log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
1927 /* JVM_GetCPClassNameUTF */
1929 const char *JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1931 log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
1937 /* JVM_GetCPFieldClassNameUTF */
1939 const char *JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1941 log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
1947 /* JVM_GetCPMethodClassNameUTF */
1949 const char *JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1951 log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
1957 /* JVM_GetCPFieldModifiers */
1959 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1961 log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
1967 /* JVM_GetCPMethodModifiers */
1969 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1971 log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
1977 /* JVM_ReleaseUTF */
1979 void JVM_ReleaseUTF(const char *utf)
1981 log_println("JVM_ReleaseUTF: IMPLEMENT ME!");
1985 /* JVM_IsSameClassPackage */
1987 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
1989 log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
1997 /* Taken from: hotspot/src/share/vm/prims/jvm.h */
2000 * JVM I/O error codes
2002 #define JVM_EEXIST -100
2004 jint JVM_Open(const char* fname, jint flags, jint mode)
2008 TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
2010 HPI& hpi = VM::get_current()->get_hpi();
2011 result = hpi.get_file().Open(fname, flags, mode);
2029 jint JVM_Close(jint fd)
2031 TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
2033 HPI& hpi = VM::get_current()->get_hpi();
2034 return hpi.get_file().Close(fd);
2040 jint JVM_Read(jint fd, char* buf, jint nbytes)
2042 TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
2044 HPI& hpi = VM::get_current()->get_hpi();
2045 return (jint) hpi.get_file().Read(fd, buf, nbytes);
2051 jint JVM_Write(jint fd, char* buf, jint nbytes)
2053 TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
2055 HPI& hpi = VM::get_current()->get_hpi();
2056 return (jint) hpi.get_file().Write(fd, buf, nbytes);
2062 jint JVM_Available(jint fd, jlong* pbytes)
2064 TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
2066 HPI& hpi = VM::get_current()->get_hpi();
2067 return hpi.get_file().Available(fd, pbytes);
2073 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
2075 TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
2077 HPI& hpi = VM::get_current()->get_hpi();
2078 return hpi.get_file().Seek(fd, (off_t) offset, whence);
2084 jint JVM_SetLength(jint fd, jlong length)
2086 TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
2088 HPI& hpi = VM::get_current()->get_hpi();
2089 return hpi.get_file().SetLength(fd, length);
2095 jint JVM_Sync(jint fd)
2097 TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
2099 HPI& hpi = VM::get_current()->get_hpi();
2100 return hpi.get_file().Sync(fd);
2104 /* JVM_StartThread */
2106 void JVM_StartThread(JNIEnv* env, jobject jthread)
2108 TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
2110 threads_thread_start((java_handle_t *) jthread);
2114 /* JVM_StopThread */
2116 void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
2118 log_println("JVM_StopThread: Deprecated. Not implemented.");
2122 /* JVM_IsThreadAlive */
2124 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
2130 TRACEJVMCALLS(("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread));
2132 h = (java_handle_t *) jthread;
2133 t = thread_get_thread(h);
2135 /* The threadobject is null when a thread is created in Java. The
2136 priority is set later during startup. */
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);
2244 threads_thread_interrupt(t);
2248 /* JVM_IsInterrupted */
2250 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2254 jboolean interrupted;
2256 TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
2258 h = (java_handle_t *) jthread;
2259 t = thread_get_thread(h);
2261 interrupted = thread_is_interrupted(t);
2263 if (interrupted && clear_interrupted)
2264 thread_set_interrupted(t, false);
2272 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2277 TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
2279 h = (java_handle_t *) obj;
2282 exceptions_throw_nullpointerexception();
2286 result = lock_is_held_by_current_thread(h);
2292 /* JVM_DumpAllStacks */
2294 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2296 log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2300 /* JVM_CurrentLoadedClass */
2302 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2304 log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2310 /* JVM_CurrentClassLoader */
2312 jobject JVM_CurrentClassLoader(JNIEnv *env)
2314 /* XXX if a method in a class in a trusted loader is in a
2315 doPrivileged, return NULL */
2317 log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2323 /* JVM_GetClassContext */
2325 jobjectArray JVM_GetClassContext(JNIEnv *env)
2327 TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
2329 return (jobjectArray) stacktrace_getClassContext();
2333 /* JVM_ClassDepth */
2335 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2337 log_println("JVM_ClassDepth: IMPLEMENT ME!");
2343 /* JVM_ClassLoaderDepth */
2345 jint JVM_ClassLoaderDepth(JNIEnv *env)
2347 log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2353 /* JVM_GetSystemPackage */
2355 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2361 TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
2363 /* s = Package::find(name); */
2364 u = javastring_toutf((java_handle_t *) name, false);
2366 result = Package::find(u);
2369 s = javastring_new(result);
2377 /* JVM_GetSystemPackages */
2379 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2381 log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2387 /* JVM_AllocateNewObject */
2389 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2391 log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2397 /* JVM_AllocateNewArray */
2399 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2401 log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2407 /* JVM_LatestUserDefinedLoader */
2409 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2413 TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
2415 cl = stacktrace_first_nonnull_classloader();
2417 return (jobject) cl;
2421 /* JVM_LoadClass0 */
2423 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2425 log_println("JVM_LoadClass0: IMPLEMENT ME!");
2431 /* JVM_GetArrayLength */
2433 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2437 TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
2439 a = (java_handle_t *) arr;
2441 return array_length_get(a);
2445 /* JVM_GetArrayElement */
2447 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2452 TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
2454 a = (java_handle_t *) arr;
2456 /* if (!class_is_array(a->objheader.vftbl->class)) { */
2457 /* exceptions_throw_illegalargumentexception(); */
2461 o = array_element_get(a, index);
2467 /* JVM_GetPrimitiveArrayElement */
2469 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2473 log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2481 /* JVM_SetArrayElement */
2483 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2486 java_handle_t *value;
2488 TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
2490 a = (java_handle_t *) arr;
2491 value = (java_handle_t *) val;
2493 array_element_set(a, index, value);
2497 /* JVM_SetPrimitiveArrayElement */
2499 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2501 log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2507 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2512 java_handle_objectarray_t *oa;
2514 TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
2516 if (eltClass == NULL) {
2517 exceptions_throw_nullpointerexception();
2521 /* NegativeArraySizeException is checked in builtin_newarray. */
2523 c = LLNI_classinfo_unwrap(eltClass);
2525 /* Create primitive or object array. */
2527 if (class_is_primitive(c)) {
2528 pc = Primitive::get_arrayclass_by_name(c->name);
2530 /* void arrays are not allowed. */
2533 exceptions_throw_illegalargumentexception();
2537 a = builtin_newarray(length, pc);
2542 oa = builtin_anewarray(length, c);
2544 return (jobject) oa;
2549 /* JVM_NewMultiArray */
2551 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2554 java_handle_intarray_t *ia;
2560 java_handle_objectarray_t *a;
2562 TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
2564 if (eltClass == NULL) {
2565 exceptions_throw_nullpointerexception();
2569 /* NegativeArraySizeException is checked in builtin_newarray. */
2571 c = LLNI_classinfo_unwrap(eltClass);
2573 ia = (java_handle_intarray_t *) dim;
2575 length = array_length_get((java_handle_t *) ia);
2577 /* We check here for exceptions thrown in array_length_get,
2578 otherwise these exceptions get overwritten by the following
2579 IllegalArgumentException. */
2584 if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
2585 exceptions_throw_illegalargumentexception();
2589 /* XXX This is just a quick hack to get it working. */
2591 dims = MNEW(long, length);
2593 for (i = 0; i < length; i++) {
2594 value = LLNI_array_direct(ia, i);
2595 dims[i] = (long) value;
2598 /* Create an array-class if necessary. */
2600 if (class_is_primitive(c)) {
2601 ac = Primitive::get_arrayclass_by_name(c->name);
2603 // Arrays of void are not allowed.
2605 exceptions_throw_illegalargumentexception();
2610 ac = class_multiarray_of((length - 1), ac, true);
2613 ac = class_multiarray_of(length, c, true);
2618 /* Allocate a new array on the heap. */
2620 a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
2626 /* JVM_InitializeSocketLibrary */
2628 jint JVM_InitializeSocketLibrary()
2630 TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
2632 HPI& hpi = VM::get_current()->get_hpi();
2633 return hpi.initialize_socket_library();
2639 jint JVM_Socket(jint domain, jint type, jint protocol)
2641 TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
2643 return os::socket(domain, type, protocol);
2647 /* JVM_SocketClose */
2649 jint JVM_SocketClose(jint fd)
2651 TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
2653 return os::close(fd);
2657 /* JVM_SocketShutdown */
2659 jint JVM_SocketShutdown(jint fd, jint howto)
2661 TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
2663 return os::shutdown(fd, howto);
2669 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2671 log_println("JVM_Recv: IMPLEMENT ME!");
2679 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2681 TRACEJVMCALLSENTER(("JVM_Send(fd=%d, buf=%p, nBytes=%d, flags=%d", fd, buf, nBytes, flags));
2683 int result = os::send(fd, buf, nBytes, flags);
2685 TRACEJVMCALLSEXIT(("->%d", result));
2693 jint JVM_Timeout(int fd, long timeout)
2695 log_println("JVM_Timeout: IMPLEMENT ME!");
2703 jint JVM_Listen(jint fd, jint count)
2705 TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
2707 return os::listen(fd, count);
2713 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2715 TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
2717 return os::connect(fd, him, len);
2723 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2725 log_println("JVM_Bind: IMPLEMENT ME!");
2733 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2735 TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
2737 return os::accept(fd, him, (socklen_t *) len);
2743 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2745 log_println("JVM_RecvFrom: IMPLEMENT ME!");
2751 /* JVM_GetSockName */
2753 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2755 TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
2757 return os::getsockname(fd, him, (socklen_t *) len);
2763 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2765 log_println("JVM_SendTo: IMPLEMENT ME!");
2771 /* JVM_SocketAvailable */
2773 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2775 #if defined(FIONREAD)
2779 TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
2783 result = ioctl(fd, FIONREAD, &bytes);
2792 # error FIONREAD not defined
2797 /* JVM_GetSockOpt */
2799 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2801 TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
2803 return os::getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
2807 /* JVM_SetSockOpt */
2809 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2811 TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
2813 return os::setsockopt(fd, level, optname, optval, optlen);
2817 /* JVM_GetHostName */
2819 int JVM_GetHostName(char *name, int namelen)
2823 TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
2825 result = os::gethostname(name, namelen);
2827 TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
2833 /* JVM_GetHostByAddr */
2835 struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
2837 log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2843 /* JVM_GetHostByName */
2845 struct hostent *JVM_GetHostByName(char* name)
2847 log_println("JVM_GetHostByName: IMPLEMENT ME!");
2853 /* JVM_GetProtoByName */
2855 struct protoent *JVM_GetProtoByName(char* name)
2857 log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2863 /* JVM_LoadLibrary */
2865 void* JVM_LoadLibrary(const char* name)
2867 TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
2869 utf* u = utf_new_char(name);
2871 NativeLibrary nl(u);
2872 void* handle = nl.open();
2874 TRACEJVMCALLSEXIT(("->%p", handle));
2880 /* JVM_UnloadLibrary */
2882 void JVM_UnloadLibrary(void* handle)
2884 TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
2886 NativeLibrary nl(handle);
2891 /* JVM_FindLibraryEntry */
2893 void *JVM_FindLibraryEntry(void* handle, const char* name)
2897 TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
2899 HPI& hpi = VM::get_current()->get_hpi();
2900 symbol = hpi.get_library().FindLibraryEntry(handle, name);
2902 TRACEJVMCALLSEXIT(("->%p", symbol));
2910 jboolean JVM_IsNaN(jdouble d)
2914 TRACEJVMCALLSENTER(("JVM_IsNaN(d=%f)", d));
2918 TRACEJVMCALLSEXIT(("->%d", result));
2924 /* JVM_IsSupportedJNIVersion */
2926 jboolean JVM_IsSupportedJNIVersion(jint version)
2928 TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
2930 return jni_version_check(version);
2934 /* JVM_InternString */
2936 jstring JVM_InternString(JNIEnv *env, jstring str)
2938 TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
2940 return (jstring) javastring_intern((java_handle_t *) str);
2944 /* JVM_RawMonitorCreate */
2946 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
2948 TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
2950 Mutex* m = new Mutex();
2956 /* JVM_RawMonitorDestroy */
2958 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void* mon)
2960 TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
2962 delete ((Mutex*) mon);
2966 /* JVM_RawMonitorEnter */
2968 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void* mon)
2970 TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
2972 ((Mutex*) mon)->lock();
2978 /* JVM_RawMonitorExit */
2980 JNIEXPORT void JNICALL JVM_RawMonitorExit(void* mon)
2982 TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
2984 ((Mutex*) mon)->unlock();
2988 /* JVM_SetPrimitiveFieldValues */
2990 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
2992 log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
2996 /* JVM_GetPrimitiveFieldValues */
2998 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3000 log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
3004 /* JVM_AccessVMBooleanFlag */
3006 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
3008 log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
3014 /* JVM_AccessVMIntFlag */
3016 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
3018 log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
3024 /* JVM_VMBreakPoint */
3026 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
3028 log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
3032 /* JVM_GetClassFields */
3034 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
3036 log_println("JVM_GetClassFields: IMPLEMENT ME!");
3042 /* JVM_GetClassMethods */
3044 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
3046 log_println("JVM_GetClassMethods: IMPLEMENT ME!");
3052 /* JVM_GetClassConstructors */
3054 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
3056 log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
3062 /* JVM_GetClassField */
3064 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
3066 log_println("JVM_GetClassField: IMPLEMENT ME!");
3072 /* JVM_GetClassMethod */
3074 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
3076 log_println("JVM_GetClassMethod: IMPLEMENT ME!");
3082 /* JVM_GetClassConstructor */
3084 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
3086 log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
3092 /* JVM_NewInstance */
3094 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
3096 log_println("JVM_NewInstance: IMPLEMENT ME!");
3104 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
3106 log_println("JVM_GetField: IMPLEMENT ME!");
3112 /* JVM_GetPrimitiveField */
3114 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
3118 log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
3128 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
3130 log_println("JVM_SetField: IMPLEMENT ME!");
3134 /* JVM_SetPrimitiveField */
3136 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
3138 log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
3142 /* JVM_InvokeMethod */
3144 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
3146 TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
3148 java_lang_reflect_Method jlrm(method);
3150 java_handle_t* result = jlrm.invoke((java_handle_t*) obj, (java_handle_objectarray_t*) args0);
3152 return (jobject) result;
3156 /* JVM_NewInstanceFromConstructor */
3158 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
3160 TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
3162 java_lang_reflect_Constructor jlrc(con);
3163 java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args0);
3169 /* JVM_SupportsCX8 */
3171 jboolean JVM_SupportsCX8()
3173 TRACEJVMCALLS(("JVM_SupportsCX8()"));
3183 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
3185 log_println("JVM_CX8Field: IMPLEMENT ME!");
3191 /* JVM_GetAllThreads */
3193 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
3195 log_println("JVM_GetAllThreads: IMPLEMENT ME!");
3201 /* JVM_DumpThreads */
3203 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
3207 TRACEJVMCALLS(("JVM_DumpThreads((env=%p, threadClass=%p, threads=%p)", env, threadClass, threads));
3209 if (threads == NULL) {
3210 exceptions_throw_nullpointerexception();
3214 // Get length of the threads array.
3215 int32_t length = array_length_get((java_handle_t*) threads);
3218 exceptions_throw_illegalargumentexception();
3222 // Allocate array to hold stacktraces.
3223 classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
3224 java_handle_objectarray_t* oas = builtin_anewarray(length, arrayclass);
3230 // Iterate over all passed thread objects.
3231 for (i = 0; i < length; i++) {
3232 java_handle_t* thread = array_objectarray_element_get(threads, i);
3234 // Get thread for the given thread object.
3235 threadobject* t = thread_get_thread(thread);
3240 // Get stacktrace for given thread.
3241 stacktrace_t* st = stacktrace_get_of_thread(t);
3246 // Convert stacktrace into array of StackTraceElements.
3247 java_handle_objectarray_t* oa = stacktrace_get_StackTraceElements(st);
3249 array_objectarray_element_set(oas, i, (java_handle_t*) oa);
3256 /* JVM_GetManagement */
3258 void *JVM_GetManagement(jint version)
3260 TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
3262 return Management::get_jmm_interface(version);
3266 /* JVM_InitAgentProperties */
3268 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
3270 log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
3276 /* JVM_GetEnclosingMethodInfo */
3278 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
3282 java_handle_objectarray_t *oa;
3284 TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
3286 c = LLNI_classinfo_unwrap(ofClass);
3288 if ((c == NULL) || class_is_primitive(c))
3291 m = class_get_enclosingmethod_raw(c);
3296 oa = builtin_anewarray(3, class_java_lang_Object);
3301 array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
3302 array_objectarray_element_set(oa, 1, javastring_new(m->name));
3303 array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
3305 return (jobjectArray) oa;
3309 /* JVM_GetThreadStateValues */
3311 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
3313 java_handle_intarray_t *ia;
3315 TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
3316 env, javaThreadState));
3318 /* If new thread states are added in future JDK and VM versions,
3319 this should check if the JDK version is compatible with thread
3320 states supported by the VM. Return NULL if not compatible.
3322 This function must map the VM java_lang_Thread::ThreadStatus
3323 to the Java thread state that the JDK supports. */
3325 switch (javaThreadState) {
3326 case THREAD_STATE_NEW:
3327 ia = builtin_newarray_int(1);
3332 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
3335 case THREAD_STATE_RUNNABLE:
3336 ia = builtin_newarray_int(1);
3341 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
3344 case THREAD_STATE_BLOCKED:
3345 ia = builtin_newarray_int(1);
3350 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
3353 case THREAD_STATE_WAITING:
3354 ia = builtin_newarray_int(2);
3359 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
3360 array_intarray_element_set(ia, 1, THREAD_STATE_PARKED);
3363 case THREAD_STATE_TIMED_WAITING:
3364 ia = builtin_newarray_int(2);
3369 /* XXX Not sure about that one. */
3370 /* array_intarray_element_set(ia, 0, SLEEPING); */
3371 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
3372 array_intarray_element_set(ia, 1, THREAD_STATE_TIMED_PARKED);
3375 case THREAD_STATE_TERMINATED:
3376 ia = builtin_newarray_int(1);
3381 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
3385 /* Unknown state - probably incompatible JDK version */
3389 return (jintArray) ia;
3393 /* JVM_GetThreadStateNames */
3395 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
3397 java_handle_intarray_t *ia;
3398 java_handle_objectarray_t *oa;
3401 TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
3402 env, javaThreadState, values));
3404 ia = (java_handle_intarray_t *) values;
3406 /* If new thread states are added in future JDK and VM versions,
3407 this should check if the JDK version is compatible with thread
3408 states supported by the VM. Return NULL if not compatible.
3410 This function must map the VM java_lang_Thread::ThreadStatus
3411 to the Java thread state that the JDK supports. */
3413 if (values == NULL) {
3414 exceptions_throw_nullpointerexception();
3418 switch (javaThreadState) {
3419 case THREAD_STATE_NEW:
3420 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
3422 oa = builtin_anewarray(1, class_java_lang_String);
3427 s = javastring_new(utf_new_char("NEW"));
3432 array_objectarray_element_set(oa, 0, s);
3435 case THREAD_STATE_RUNNABLE:
3436 oa = builtin_anewarray(1, class_java_lang_String);
3441 s = javastring_new(utf_new_char("RUNNABLE"));
3446 array_objectarray_element_set(oa, 0, s);
3449 case THREAD_STATE_BLOCKED:
3450 oa = builtin_anewarray(1, class_java_lang_String);
3455 s = javastring_new(utf_new_char("BLOCKED"));
3460 array_objectarray_element_set(oa, 0, s);
3463 case THREAD_STATE_WAITING:
3464 oa = builtin_anewarray(2, class_java_lang_String);
3469 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
3474 array_objectarray_element_set(oa, 0, s);
3476 s = javastring_new(utf_new_char("WAITING.PARKED"));
3481 array_objectarray_element_set(oa, 1, s);
3484 case THREAD_STATE_TIMED_WAITING:
3485 oa = builtin_anewarray(2, class_java_lang_String);
3490 /* s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
3491 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
3496 array_objectarray_element_set(oa, 0, s);
3498 s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
3503 array_objectarray_element_set(oa, 1, s);
3506 case THREAD_STATE_TERMINATED:
3507 oa = builtin_anewarray(1, class_java_lang_String);
3512 s = javastring_new(utf_new_char("TERMINATED"));
3517 array_objectarray_element_set(oa, 0, s);
3521 /* Unknown state - probably incompatible JDK version */
3525 return (jobjectArray) oa;
3529 /* JVM_GetVersionInfo */
3531 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3533 log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3537 /* OS: JVM_RegisterSignal */
3539 void *JVM_RegisterSignal(jint sig, void *handler)
3541 functionptr newHandler;
3543 TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
3545 if (handler == (void *) 2)
3546 newHandler = (functionptr) signal_thread_handler;
3548 newHandler = (functionptr) (uintptr_t) handler;
3555 /* These signals are already used by the VM. */
3559 /* This signal is used by the VM to dump thread stacks unless
3560 ReduceSignalUsage is set, in which case the user is allowed
3561 to set his own _native_ handler for this signal; thus, in
3562 either case, we do not allow JVM_RegisterSignal to change
3572 signal_register_signal(sig, newHandler, SA_RESTART | SA_SIGINFO);
3574 /* XXX Should return old handler. */
3580 /* OS: JVM_RaiseSignal */
3582 jboolean JVM_RaiseSignal(jint sig)
3584 log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3590 /* OS: JVM_FindSignal */
3592 jint JVM_FindSignal(const char *name)
3594 TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
3596 #if defined(__LINUX__)
3597 if (strcmp(name, "HUP") == 0)
3600 if (strcmp(name, "INT") == 0)
3603 if (strcmp(name, "TERM") == 0)
3605 #elif defined(__SOLARIS__)
3608 if (os::str2sig(name, &signum) == -1)
3613 # error Not implemented for this OS.
3623 * These are local overrides for various environment variables in Emacs.
3624 * Please do not remove this and leave it at the end of the file, where
3625 * Emacs will automagically detect them.
3626 * ---------------------------------------------------------------------
3629 * indent-tabs-mode: t
3633 * vim:noexpandtab:sw=4:ts=4: