* configure.ac (AC_CHECK_WITH_HPI_MD_H): Added.
[cacao.git] / src / native / vm / sun / jvm.c
1 /* src/native/vm/sun/jvm.c - HotSpot JVM interface functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <errno.h>
30 #include <ltdl.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <unistd.h>
35
36 #if defined(HAVE_SYS_IOCTL_H)
37 #define BSD_COMP /* Get FIONREAD on Solaris2 */
38 #include <sys/ioctl.h>
39 #endif
40
41 #include <sys/socket.h>
42 #include <sys/stat.h>
43 #include <sys/types.h>
44
45 #include "vm/types.h"
46
47 #include "mm/memory.h"
48
49 #include "native/jni.h"
50 #include "native/llni.h"
51 #include "native/native.h"
52
53 #include "native/include/java_lang_AssertionStatusDirectives.h"
54 #include "native/include/java_lang_String.h"            /* required by j.l.CL */
55 #include "native/include/java_nio_ByteBuffer.h"         /* required by j.l.CL */
56 #include "native/include/java_lang_ClassLoader.h"        /* required by j.l.C */
57 #include "native/include/java_lang_StackTraceElement.h"
58 #include "native/include/java_lang_Throwable.h"
59 #include "native/include/java_security_ProtectionDomain.h"
60
61 #if defined(ENABLE_ANNOTATIONS)
62 #include "native/include/sun_reflect_ConstantPool.h"
63 #endif
64
65 #include "native/vm/java_lang_Class.h"
66 #include "native/vm/java_lang_reflect_Constructor.h"
67 #include "native/vm/java_lang_reflect_Method.h"
68 #include "native/vm/reflect.h"
69
70 #include "native/vm/sun/hpi.h"
71
72 #include "threads/lock-common.h"
73 #include "threads/threads-common.h"
74
75 #include "toolbox/logging.h"
76 #include "toolbox/list.h"
77
78 #include "vm/array.h"
79
80 #if defined(ENABLE_ASSERTION)
81 #include "vm/assertion.h"
82 #endif
83
84 #include "vm/builtin.h"
85 #include "vm/exceptions.h"
86 #include "vm/global.h"
87 #include "vm/initialize.h"
88 #include "vm/package.h"
89 #include "vm/primitive.h"
90 #include "vm/properties.h"
91 #include "vm/resolve.h"
92 #include "vm/signallocal.h"
93 #include "vm/stringlocal.h"
94 #include "vm/vm.h"
95
96 #include "vm/jit/stacktrace.h"
97
98 #include "vmcore/classcache.h"
99 #include "vmcore/options.h"
100 #include "vmcore/system.h"
101
102
103 /* debugging macros ***********************************************************/
104
105 #if !defined(NDEBUG)
106
107 # define TRACEJVMCALLS(x)                                                                               \
108     do {                                                                                                                \
109         if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {    \
110             log_println x;                                                                              \
111         }                                                                                                               \
112     } while (0)
113
114 # define TRACEJVMCALLSVERBOSE(x)                                \
115     do {                                                                                \
116         if (opt_TraceJVMCallsVerbose) {                 \
117             log_println x;                                              \
118         }                                                                               \
119     } while (0)
120
121 # define PRINTJVMWARNINGS(x)
122 /*     do { \ */
123 /*         if (opt_PrintJVMWarnings) { \ */
124 /*             log_println x; \ */
125 /*         } \ */
126 /*     } while (0) */
127
128 #else
129
130 # define TRACEJVMCALLS(x)
131 # define TRACEJVMCALLSVERBOSE(x)
132 # define PRINTJVMWARNINGS(x)
133
134 #endif
135
136
137 typedef struct {
138     /* Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx */
139     unsigned int jvm_version;   /* Consists of major, minor, micro (n.n.n) */
140                                 /* and build number (xx) */
141     unsigned int update_version : 8;         /* Update release version (uu) */
142     unsigned int special_update_version : 8; /* Special update release version (c) */
143     unsigned int reserved1 : 16; 
144     unsigned int reserved2; 
145
146     /* The following bits represents JVM supports that JDK has dependency on.
147      * JDK can use these bits to determine which JVM version
148      * and support it has to maintain runtime compatibility.
149      *
150      * When a new bit is added in a minor or update release, make sure
151      * the new bit is also added in the main/baseline.
152      */
153     unsigned int is_attachable : 1;
154     unsigned int : 31;
155     unsigned int : 32;
156     unsigned int : 32;
157 } jvm_version_info;
158
159
160 /*
161  * A structure used to a capture exception table entry in a Java method.
162  */
163 typedef struct {
164     jint start_pc;
165     jint end_pc;
166     jint handler_pc;
167     jint catchType;
168 } JVM_ExceptionTableEntryType;
169
170
171 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
172 {
173         if ((intptr_t) count <= 0)
174                 return -1;
175
176         return vsnprintf(str, count, fmt, args);
177 }
178
179
180 int jio_snprintf(char *str, size_t count, const char *fmt, ...)
181 {
182         va_list ap;
183         int     len;
184
185         va_start(ap, fmt);
186         len = jio_vsnprintf(str, count, fmt, ap);
187         va_end(ap);
188
189         return len;
190 }
191
192
193 int jio_fprintf(FILE* f, const char *fmt, ...)
194 {
195         log_println("jio_fprintf: IMPLEMENT ME!");
196
197         return 0;
198 }
199
200
201 int jio_vfprintf(FILE* f, const char *fmt, va_list args)
202 {
203         log_println("jio_vfprintf: IMPLEMENT ME!");
204
205         return 0;
206 }
207
208
209 int jio_printf(const char *fmt, ...)
210 {
211         log_println("jio_printf: IMPLEMENT ME!");
212
213         return 0;
214 }
215
216
217 /* JVM_GetInterfaceVersion */
218
219 jint JVM_GetInterfaceVersion()
220 {
221         /* This is defined in hotspot/src/share/vm/prims/jvm.h */
222
223 #define JVM_INTERFACE_VERSION 4
224
225         return JVM_INTERFACE_VERSION;
226 }
227
228
229 /* JVM_CurrentTimeMillis */
230
231 jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
232 {
233         TRACEJVMCALLS(("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored));
234
235         return (jlong) builtin_currenttimemillis();
236 }
237
238
239 /* JVM_NanoTime */
240
241 jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
242 {
243         TRACEJVMCALLS(("JVM_NanoTime(env=%p, ignored=%p)", env, ignored));
244
245         return (jlong) builtin_nanotime();
246 }
247
248
249 /* JVM_ArrayCopy */
250
251 void JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length)
252 {
253         java_handle_t *s;
254         java_handle_t *d;
255
256         s = (java_handle_t *) src;
257         d = (java_handle_t *) dst;
258
259         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));
260
261         builtin_arraycopy(s, src_pos, d, dst_pos, length);
262 }
263
264
265 /* JVM_InitProperties */
266
267 jobject JVM_InitProperties(JNIEnv *env, jobject properties)
268 {
269         java_handle_t *h;
270         char           buf[256];
271
272         TRACEJVMCALLS(("JVM_InitProperties(env=%p, properties=%p)", env, properties));
273
274         h = (java_handle_t *) properties;
275
276         /* Convert the -XX:MaxDirectMemorySize= command line flag to the
277            sun.nio.MaxDirectMemorySize property.  Do this after setting
278            user properties to prevent people from setting the value with a
279            -D option, as requested. */
280
281         jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
282         properties_add("sun.nio.MaxDirectMemorySize", buf);
283
284         /* Add all properties. */
285
286         properties_system_add_all(h);
287
288         return properties;
289 }
290
291
292 /* JVM_Exit */
293
294 void JVM_Exit(jint code)
295 {
296         log_println("JVM_Exit: IMPLEMENT ME!");
297 }
298
299
300 /* JVM_Halt */
301
302 void JVM_Halt(jint code)
303 {
304         TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
305
306 /*      vm_exit(code); */
307         vm_shutdown(code);
308 }
309
310
311 /* JVM_OnExit(void (*func)) */
312
313 void JVM_OnExit(void (*func)(void))
314 {
315         log_println("JVM_OnExit(void (*func): IMPLEMENT ME!");
316 }
317
318
319 /* JVM_GC */
320
321 void JVM_GC(void)
322 {
323         TRACEJVMCALLS(("JVM_GC()"));
324
325         gc_call();
326 }
327
328
329 /* JVM_MaxObjectInspectionAge */
330
331 jlong JVM_MaxObjectInspectionAge(void)
332 {
333         log_println("JVM_MaxObjectInspectionAge: IMPLEMENT ME!");
334
335         return 0;
336 }
337
338
339 /* JVM_TraceInstructions */
340
341 void JVM_TraceInstructions(jboolean on)
342 {
343         log_println("JVM_TraceInstructions: IMPLEMENT ME!");
344 }
345
346
347 /* JVM_TraceMethodCalls */
348
349 void JVM_TraceMethodCalls(jboolean on)
350 {
351         log_println("JVM_TraceMethodCalls: IMPLEMENT ME!");
352 }
353
354
355 /* JVM_TotalMemory */
356
357 jlong JVM_TotalMemory(void)
358 {
359         TRACEJVMCALLS(("JVM_TotalMemory()"));
360
361         return gc_get_heap_size();
362 }
363
364
365 /* JVM_FreeMemory */
366
367 jlong JVM_FreeMemory(void)
368 {
369         TRACEJVMCALLS(("JVM_FreeMemory()"));
370
371         return gc_get_free_bytes();
372 }
373
374
375 /* JVM_MaxMemory */
376
377 jlong JVM_MaxMemory(void)
378 {
379         TRACEJVMCALLS(("JVM_MaxMemory()"));
380
381         return gc_get_max_heap_size();
382 }
383
384
385 /* JVM_ActiveProcessorCount */
386
387 jint JVM_ActiveProcessorCount(void)
388 {
389         TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
390
391         return system_processors_online();
392 }
393
394
395 /* JVM_FillInStackTrace */
396
397 void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
398 {
399         java_lang_Throwable     *o;
400         java_handle_bytearray_t *ba;
401
402         TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
403
404         o = (java_lang_Throwable *) receiver;
405
406         ba = stacktrace_get_current();
407
408         if (ba == NULL)
409                 return;
410
411         LLNI_field_set_ref(o, backtrace, (java_lang_Object *) ba);
412 }
413
414
415 /* JVM_PrintStackTrace */
416
417 void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
418 {
419         log_println("JVM_PrintStackTrace: IMPLEMENT ME!");
420 }
421
422
423 /* JVM_GetStackTraceDepth */
424
425 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
426 {
427         java_lang_Throwable     *to;
428         java_lang_Object        *o;
429         java_handle_bytearray_t *ba;
430         stacktrace_t            *st;
431         int32_t                  depth;
432
433         TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
434
435         if (throwable == NULL) {
436                 exceptions_throw_nullpointerexception();
437                 return 0;
438         }
439
440         to = (java_lang_Throwable *) throwable;
441
442         LLNI_field_get_ref(to, backtrace, o);
443
444         ba = (java_handle_bytearray_t *) o;
445
446         if (ba == NULL)
447                 return 0;
448
449         /* We need a critical section here as the stacktrace structure is
450            mapped onto a Java byte-array. */
451
452         LLNI_CRITICAL_START;
453
454         st = (stacktrace_t *) LLNI_array_data(ba);
455
456         depth = st->length;
457
458         LLNI_CRITICAL_END;
459
460         return depth;
461 }
462
463
464 /* JVM_GetStackTraceElement */
465
466 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
467 {
468         java_lang_Throwable         *to;
469         java_lang_Object            *o;
470         java_handle_bytearray_t     *ba;
471         stacktrace_t                *st;
472         stacktrace_entry_t          *ste;
473         codeinfo                    *code;
474         methodinfo                  *m;
475         classinfo                   *c;
476         java_lang_StackTraceElement *steo;
477         java_lang_String            *declaringclass;
478         java_lang_String            *filename;
479         int32_t                      linenumber;
480
481         TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
482
483         to = (java_lang_Throwable *) throwable;
484
485         LLNI_field_get_ref(to, backtrace, o);
486
487         ba = (java_handle_bytearray_t *) o;
488
489         /* FIXME critical section */
490
491         st = (stacktrace_t *) LLNI_array_data(ba);
492
493         if ((index < 0) || (index >= st->length)) {
494                 /* XXX This should be an IndexOutOfBoundsException (check this
495                    again). */
496
497                 exceptions_throw_arrayindexoutofboundsexception();
498                 return NULL;
499         }
500
501         /* Get the stacktrace entry. */
502
503         ste = &(st->entries[index]);
504
505         /* Get the codeinfo, methodinfo and classinfo. */
506
507         code = ste->code;
508         m    = code->m;
509         c    = m->class;
510
511         /* allocate a new StackTraceElement */
512
513         steo = (java_lang_StackTraceElement *)
514                 builtin_new(class_java_lang_StackTraceElement);
515
516         if (steo == NULL)
517                 return NULL;
518
519         /* get filename */
520
521         if (!(m->flags & ACC_NATIVE)) {
522                 if (c->sourcefile != NULL)
523                         filename = (java_lang_String *) javastring_new(c->sourcefile);
524                 else
525                         filename = NULL;
526         }
527         else
528                 filename = NULL;
529
530         /* get line number */
531
532         if (m->flags & ACC_NATIVE) {
533                 linenumber = -2;
534         }
535         else {
536                 /* FIXME The linenumbertable_linenumber_for_pc could change
537                    the methodinfo pointer when hitting an inlined method. */
538
539                 linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
540                 linenumber = (linenumber == 0) ? -1 : linenumber;
541         }
542
543         /* get declaring class name */
544
545         declaringclass = _Jv_java_lang_Class_getName(LLNI_classinfo_wrap(c));
546
547         /* fill the java.lang.StackTraceElement element */
548
549         /* FIXME critical section */
550
551         steo->declaringClass = declaringclass;
552         steo->methodName     = (java_lang_String *) javastring_new(m->name);
553         steo->fileName       = filename;
554         steo->lineNumber     = linenumber;
555
556         return (jobject) steo;
557 }
558
559
560 /* JVM_IHashCode */
561
562 jint JVM_IHashCode(JNIEnv* env, jobject handle)
563 {
564         TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
565
566         return (jint) ((ptrint) handle);
567 }
568
569
570 /* JVM_MonitorWait */
571
572 void JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)
573 {
574 #if defined(ENABLE_THREADS)
575         java_handle_t *o;
576 #endif
577
578         TRACEJVMCALLS(("JVM_MonitorWait(env=%p, handle=%p, ms=%ld)", env, handle, ms));
579     if (ms < 0) {
580 /*              exceptions_throw_illegalargumentexception("argument out of range"); */
581                 exceptions_throw_illegalargumentexception();
582                 return;
583         }
584
585 #if defined(ENABLE_THREADS)
586         o = (java_handle_t *) handle;
587
588         lock_wait_for_object(o, ms, 0);
589 #endif
590 }
591
592
593 /* JVM_MonitorNotify */
594
595 void JVM_MonitorNotify(JNIEnv* env, jobject handle)
596 {
597 #if defined(ENABLE_THREADS)
598         java_handle_t *o;
599 #endif
600
601         TRACEJVMCALLS(("JVM_MonitorNotify(env=%p, handle=%p)", env, handle));
602
603 #if defined(ENABLE_THREADS)
604         o = (java_handle_t *) handle;
605
606         lock_notify_object(o);
607 #endif
608 }
609
610
611 /* JVM_MonitorNotifyAll */
612
613 void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
614 {
615 #if defined(ENABLE_THREADS)
616         java_handle_t *o;
617 #endif
618
619         TRACEJVMCALLS(("JVM_MonitorNotifyAll(env=%p, handle=%p)", env, handle));
620
621 #if defined(ENABLE_THREADS)
622         o = (java_handle_t *) handle;
623
624         lock_notify_all_object(o);
625 #endif
626 }
627
628
629 /* JVM_Clone */
630
631 jobject JVM_Clone(JNIEnv* env, jobject handle)
632 {
633         TRACEJVMCALLS(("JVM_Clone(env=%p, handle=%p)", env, handle));
634
635         return (jobject) builtin_clone(env, (java_handle_t *) handle);
636 }
637
638
639 /* JVM_InitializeCompiler  */
640
641 void JVM_InitializeCompiler (JNIEnv *env, jclass compCls)
642 {
643         log_println("JVM_InitializeCompiler : IMPLEMENT ME!");
644 }
645
646
647 /* JVM_IsSilentCompiler */
648
649 jboolean JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)
650 {
651         log_println("JVM_IsSilentCompiler: IMPLEMENT ME!");
652
653         return 0;
654 }
655
656
657 /* JVM_CompileClass */
658
659 jboolean JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)
660 {
661         log_println("JVM_CompileClass: IMPLEMENT ME!");
662
663         return 0;
664 }
665
666
667 /* JVM_CompileClasses */
668
669 jboolean JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)
670 {
671         log_println("JVM_CompileClasses: IMPLEMENT ME!");
672
673         return 0;
674 }
675
676
677 /* JVM_CompilerCommand */
678
679 jobject JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)
680 {
681         log_println("JVM_CompilerCommand: IMPLEMENT ME!");
682
683         return 0;
684 }
685
686
687 /* JVM_EnableCompiler */
688
689 void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
690 {
691         TRACEJVMCALLS(("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls));
692         PRINTJVMWARNINGS(("JVM_EnableCompiler not supported"));
693 }
694
695
696 /* JVM_DisableCompiler */
697
698 void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
699 {
700         TRACEJVMCALLS(("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls));
701         PRINTJVMWARNINGS(("JVM_DisableCompiler not supported"));
702 }
703
704
705 /* JVM_GetLastErrorString */
706
707 jint JVM_GetLastErrorString(char *buf, int len)
708 {
709         TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
710
711         return hpi_system->GetLastErrorString(buf, len);
712 }
713
714
715 /* JVM_NativePath */
716
717 char *JVM_NativePath(char *path)
718 {
719         TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
720
721         return hpi_file->NativePath(path);
722 }
723
724
725 /* JVM_GetCallerClass */
726
727 jclass JVM_GetCallerClass(JNIEnv* env, int depth)
728 {
729         classinfo *c;
730
731         TRACEJVMCALLS(("JVM_GetCallerClass(env=%p, depth=%d)", env, depth));
732
733         c = stacktrace_get_caller_class(depth);
734
735         return (jclass) c;
736 }
737
738
739 /* JVM_FindPrimitiveClass */
740
741 jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
742 {
743         classinfo *c;
744         utf       *u;
745
746         TRACEJVMCALLS(("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s));
747
748         u = utf_new_char(s);
749         c = primitive_class_get_by_name(u);
750
751         return (jclass) LLNI_classinfo_wrap(c);
752 }
753
754
755 /* JVM_ResolveClass */
756
757 void JVM_ResolveClass(JNIEnv* env, jclass cls)
758 {
759         TRACEJVMCALLS(("JVM_ResolveClass(env=%p, cls=%p)", env, cls));
760         PRINTJVMWARNINGS(("JVM_ResolveClass not implemented"));
761 }
762
763
764 /* JVM_FindClassFromClassLoader */
765
766 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
767 {
768         classinfo   *c;
769         utf         *u;
770         classloader *cl;
771
772         TRACEJVMCALLS(("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError));
773
774         /* As of now, OpenJDK does not call this function with throwError
775            is true. */
776
777         assert(throwError == false);
778
779         u  = utf_new_char(name);
780         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
781
782         c = load_class_from_classloader(u, cl);
783
784         if (c == NULL)
785                 return NULL;
786
787         if (init)
788                 if (!(c->state & CLASS_INITIALIZED))
789                         if (!initialize_class(c))
790                                 return NULL;
791
792         return (jclass) LLNI_classinfo_wrap(c);
793 }
794
795
796 /* JVM_FindClassFromClass */
797
798 jclass JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, jclass from)
799 {
800         log_println("JVM_FindClassFromClass: IMPLEMENT ME!");
801
802         return NULL;
803 }
804
805
806 /* JVM_DefineClass */
807
808 jclass JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)
809 {
810         log_println("JVM_DefineClass: IMPLEMENT ME!");
811
812         return NULL;
813 }
814
815
816 /* JVM_DefineClassWithSource */
817
818 jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)
819 {
820         classinfo   *c;
821         utf         *u;
822         classloader *cl;
823
824         TRACEJVMCALLS(("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source));
825
826         if (name != NULL)
827                 u = utf_new_char(name);
828         else
829                 u = NULL;
830
831         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
832
833         /* XXX do something with source */
834
835         c = class_define(u, cl, len, (uint8_t *) buf, (java_handle_t *) pd);
836
837         return (jclass) LLNI_classinfo_wrap(c);
838 }
839
840
841 /* JVM_FindLoadedClass */
842
843 jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
844 {
845         classloader *cl;
846         utf         *u;
847         classinfo   *c;
848
849         TRACEJVMCALLS(("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name));
850
851         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
852
853         u = javastring_toutf((java_handle_t *) name, true);
854         c = classcache_lookup(cl, u);
855
856         return (jclass) LLNI_classinfo_wrap(c);
857 }
858
859
860 /* JVM_GetClassName */
861
862 jstring JVM_GetClassName(JNIEnv *env, jclass cls)
863 {
864         TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
865
866         return (jstring) _Jv_java_lang_Class_getName((java_lang_Class *) cls);
867 }
868
869
870 /* JVM_GetClassInterfaces */
871
872 jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
873 {
874         classinfo                 *c;
875         java_handle_objectarray_t *oa;
876
877         TRACEJVMCALLS(("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls));
878
879         c = LLNI_classinfo_unwrap(cls);
880
881         oa = class_get_interfaces(c);
882
883         return (jobjectArray) oa;
884 }
885
886
887 /* JVM_GetClassLoader */
888
889 jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
890 {
891         classinfo   *c;
892         classloader *cl;
893
894         TRACEJVMCALLS(("JVM_GetClassLoader(env=%p, cls=%p)", env, cls));
895
896         c  = LLNI_classinfo_unwrap(cls);
897         cl = class_get_classloader(c);
898
899         return (jobject) cl;
900 }
901
902
903 /* JVM_IsInterface */
904
905 jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
906 {
907         classinfo *c;
908
909         TRACEJVMCALLS(("JVM_IsInterface(env=%p, cls=%p)", env, cls));
910
911         c = LLNI_classinfo_unwrap(cls);
912
913         return class_is_interface(c);
914 }
915
916
917 /* JVM_GetClassSigners */
918
919 jobjectArray JVM_GetClassSigners(JNIEnv *env, jclass cls)
920 {
921         log_println("JVM_GetClassSigners: IMPLEMENT ME!");
922
923         return NULL;
924 }
925
926
927 /* JVM_SetClassSigners */
928
929 void JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)
930 {
931         classinfo                 *c;
932         java_handle_objectarray_t *hoa;
933
934         TRACEJVMCALLS(("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers));
935
936         c = LLNI_classinfo_unwrap(cls);
937
938         hoa = (java_handle_objectarray_t *) signers;
939
940     /* This call is ignored for primitive types and arrays.  Signers
941            are only set once, ClassLoader.java, and thus shouldn't be
942            called with an array.  Only the bootstrap loader creates
943            arrays. */
944
945         if (class_is_primitive(c) || class_is_array(c))
946                 return;
947
948         LLNI_classinfo_field_set(c, signers, hoa);
949 }
950
951
952 /* JVM_GetProtectionDomain */
953
954 jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
955 {
956         classinfo *c;
957
958         TRACEJVMCALLS(("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls));
959
960         c = LLNI_classinfo_unwrap(cls);
961
962         if (c == NULL) {
963                 exceptions_throw_nullpointerexception();
964                 return NULL;
965         }
966
967     /* Primitive types do not have a protection domain. */
968
969         if (class_is_primitive(c))
970                 return NULL;
971
972         return (jobject) c->protectiondomain;
973 }
974
975
976 /* JVM_SetProtectionDomain */
977
978 void JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain)
979 {
980         log_println("JVM_SetProtectionDomain: IMPLEMENT ME!");
981 }
982
983
984 /* JVM_DoPrivileged */
985
986 jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
987 {
988         java_handle_t *h;
989         classinfo     *c;
990         methodinfo    *m;
991         java_handle_t *result;
992         java_handle_t *e;
993
994         TRACEJVMCALLS(("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException));
995
996         h = (java_handle_t *) action;
997         LLNI_class_get(h, c);
998
999         if (action == NULL) {
1000                 exceptions_throw_nullpointerexception();
1001                 return NULL;
1002         }
1003
1004         /* lookup run() method (throw no exceptions) */
1005
1006         m = class_resolveclassmethod(c, utf_run, utf_void__java_lang_Object, c,
1007                                                                  false);
1008
1009         if ((m == NULL) || !(m->flags & ACC_PUBLIC) || (m->flags & ACC_STATIC)) {
1010                 exceptions_throw_internalerror("No run method");
1011                 return NULL;
1012         }
1013
1014         /* XXX It seems something with a privileged stack needs to be done
1015            here. */
1016
1017         result = vm_call_method(m, h);
1018
1019         e = exceptions_get_exception();
1020
1021         if (e != NULL) {
1022                 if ( builtin_instanceof(e, class_java_lang_Exception) &&
1023                         !builtin_instanceof(e, class_java_lang_RuntimeException)) {
1024                         exceptions_clear_exception();
1025                         exceptions_throw_privilegedactionexception(e);
1026                 }
1027
1028                 return NULL;
1029         }
1030
1031         return (jobject) result;
1032 }
1033
1034
1035 /* JVM_GetInheritedAccessControlContext */
1036
1037 jobject JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)
1038 {
1039         log_println("JVM_GetInheritedAccessControlContext: IMPLEMENT ME!");
1040
1041         return NULL;
1042 }
1043
1044
1045 /* JVM_GetStackAccessControlContext */
1046
1047 jobject JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)
1048 {
1049         TRACEJVMCALLS(("JVM_GetStackAccessControlContext(env=%p, cls=%p): IMPLEMENT ME!", env, cls));
1050
1051         /* XXX All stuff I tested so far works without that function.  At
1052            some point we have to implement it, but I disable the output
1053            for now to make IcedTea happy. */
1054
1055         return NULL;
1056 }
1057
1058
1059 /* JVM_IsArrayClass */
1060
1061 jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
1062 {
1063         classinfo *c;
1064
1065         TRACEJVMCALLS(("JVM_IsArrayClass(env=%p, cls=%p)", env, cls));
1066
1067         c = LLNI_classinfo_unwrap(cls);
1068
1069         return class_is_array(c);
1070 }
1071
1072
1073 /* JVM_IsPrimitiveClass */
1074
1075 jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
1076 {
1077         classinfo *c;
1078
1079         TRACEJVMCALLS(("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls));
1080
1081         c = LLNI_classinfo_unwrap(cls);
1082
1083         return class_is_primitive(c);
1084 }
1085
1086
1087 /* JVM_GetComponentType */
1088
1089 jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
1090 {
1091         classinfo *component;
1092         classinfo *c;
1093         
1094         TRACEJVMCALLS(("JVM_GetComponentType(env=%p, cls=%p)", env, cls));
1095
1096         c = LLNI_classinfo_unwrap(cls);
1097         
1098         component = class_get_componenttype(c);
1099
1100         return (jclass) LLNI_classinfo_wrap(component);
1101 }
1102
1103
1104 /* JVM_GetClassModifiers */
1105
1106 jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
1107 {
1108         classinfo *c;
1109         int32_t    flags;
1110
1111         TRACEJVMCALLS(("JVM_GetClassModifiers(env=%p, cls=%p)", env, cls));
1112
1113         c = LLNI_classinfo_unwrap(cls);
1114
1115         flags = class_get_modifiers(c, false);
1116
1117         return flags;
1118 }
1119
1120
1121 /* JVM_GetDeclaredClasses */
1122
1123 jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
1124 {
1125         classinfo                 *c;
1126         java_handle_objectarray_t *oa;
1127
1128         TRACEJVMCALLS(("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass));
1129
1130         c = LLNI_classinfo_unwrap(ofClass);
1131
1132         oa = class_get_declaredclasses(c, false);
1133
1134         return (jobjectArray) oa;
1135 }
1136
1137
1138 /* JVM_GetDeclaringClass */
1139
1140 jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
1141 {
1142         classinfo *c;
1143         classinfo *dc;
1144
1145         TRACEJVMCALLS(("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass));
1146
1147         c = LLNI_classinfo_unwrap(ofClass);
1148
1149         dc = class_get_declaringclass(c);
1150
1151         return (jclass) LLNI_classinfo_wrap(dc);
1152 }
1153
1154
1155 /* JVM_GetClassSignature */
1156
1157 jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
1158 {
1159         classinfo     *c;
1160         utf           *u;
1161         java_handle_t *s;
1162
1163         TRACEJVMCALLS(("JVM_GetClassSignature(env=%p, cls=%p)", env, cls));
1164
1165         c = LLNI_classinfo_unwrap(cls);
1166
1167         /* Get the signature of the class. */
1168
1169         u = class_get_signature(c);
1170
1171         if (u == NULL)
1172                 return NULL;
1173
1174         /* Convert UTF-string to a Java-string. */
1175
1176         s = javastring_new(u);
1177
1178         return (jstring) s;
1179 }
1180
1181
1182 /* JVM_GetClassAnnotations */
1183
1184 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
1185 {
1186         classinfo               *c           = NULL; /* classinfo for 'cls'  */
1187         java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
1188
1189         TRACEJVMCALLS(("JVM_GetClassAnnotations: cls=%p", cls));
1190
1191         if (cls == NULL) {
1192                 exceptions_throw_nullpointerexception();
1193                 return NULL;
1194         }
1195         
1196         c = LLNI_classinfo_unwrap(cls);
1197
1198         /* get annotations: */
1199         annotations = class_get_annotations(c);
1200
1201         return (jbyteArray)annotations;
1202 }
1203
1204
1205 /* JVM_GetFieldAnnotations */
1206
1207 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
1208 {
1209         java_lang_reflect_Field *rf = NULL; /* java.lang.reflect.Field for 'field' */
1210         java_handle_bytearray_t *ba = NULL; /* unparsed annotations */
1211
1212         TRACEJVMCALLS(("JVM_GetFieldAnnotations: field=%p", field));
1213
1214         if (field == NULL) {
1215                 exceptions_throw_nullpointerexception();
1216                 return NULL;
1217         }
1218
1219         rf = (java_lang_reflect_Field*)field;
1220
1221         LLNI_field_get_ref(rf, annotations, ba);
1222
1223         return (jbyteArray)ba;
1224 }
1225
1226
1227 /* JVM_GetMethodAnnotations */
1228
1229 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
1230 {
1231         java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
1232         java_handle_bytearray_t  *ba = NULL; /* unparsed annotations */
1233
1234         TRACEJVMCALLS(("JVM_GetMethodAnnotations: method=%p", method));
1235
1236         if (method == NULL) {
1237                 exceptions_throw_nullpointerexception();
1238                 return NULL;
1239         }
1240
1241         rm = (java_lang_reflect_Method*)method;
1242
1243         LLNI_field_get_ref(rm, annotations, ba);
1244
1245         return (jbyteArray)ba;
1246 }
1247
1248
1249 /* JVM_GetMethodDefaultAnnotationValue */
1250
1251 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
1252 {
1253         java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
1254         java_handle_bytearray_t  *ba = NULL; /* unparsed annotation default value */
1255
1256         TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue: method=%p", method));
1257
1258         if (method == NULL) {
1259                 exceptions_throw_nullpointerexception();
1260                 return NULL;
1261         }
1262
1263         rm = (java_lang_reflect_Method*)method;
1264
1265         LLNI_field_get_ref(rm, annotationDefault, ba);
1266
1267         return (jbyteArray)ba;
1268 }
1269
1270
1271 /* JVM_GetMethodParameterAnnotations */
1272
1273 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
1274 {
1275         java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
1276         java_handle_bytearray_t  *ba = NULL; /* unparsed parameter annotations */
1277
1278         TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations: method=%p", method));
1279
1280         if (method == NULL) {
1281                 exceptions_throw_nullpointerexception();
1282                 return NULL;
1283         }
1284
1285         rm = (java_lang_reflect_Method*)method;
1286
1287         LLNI_field_get_ref(rm, parameterAnnotations, ba);
1288
1289         return (jbyteArray)ba;
1290 }
1291
1292
1293 /* JVM_GetClassDeclaredFields */
1294
1295 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1296 {
1297         TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1298
1299         return (jobjectArray) _Jv_java_lang_Class_getDeclaredFields((java_lang_Class *) ofClass, publicOnly);
1300 }
1301
1302
1303 /* JVM_GetClassDeclaredMethods */
1304
1305 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1306 {
1307         TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1308
1309         return (jobjectArray) _Jv_java_lang_Class_getDeclaredMethods((java_lang_Class *) ofClass, publicOnly);
1310 }
1311
1312
1313 /* JVM_GetClassDeclaredConstructors */
1314
1315 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1316 {
1317         TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1318
1319         return (jobjectArray) _Jv_java_lang_Class_getDeclaredConstructors((java_lang_Class *) ofClass, publicOnly);
1320 }
1321
1322
1323 /* JVM_GetClassAccessFlags */
1324
1325 jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
1326 {
1327         classinfo *c;
1328
1329         TRACEJVMCALLS(("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls));
1330
1331         c = LLNI_classinfo_unwrap(cls);
1332
1333         /* Primitive type classes have the correct access flags. */
1334
1335         return c->flags & ACC_CLASS_REFLECT_MASK;
1336 }
1337
1338
1339 /* JVM_GetClassConstantPool */
1340
1341 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
1342 {
1343 #if defined(ENABLE_ANNOTATIONS)
1344         sun_reflect_ConstantPool *constantPool    = NULL;
1345                       /* constant pool object for the class refered by 'cls' */
1346         java_lang_Object         *constantPoolOop = (java_lang_Object*)cls;
1347                       /* constantPoolOop field of the constant pool object   */
1348
1349         TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
1350
1351         constantPool = 
1352                 (sun_reflect_ConstantPool*)native_new_and_init(
1353                         class_sun_reflect_ConstantPool);
1354         
1355         if (constantPool == NULL) {
1356                 /* out of memory */
1357                 return NULL;
1358         }
1359         
1360         LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
1361
1362         return (jobject)constantPool;
1363 #else
1364         log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
1365         return NULL;
1366 #endif
1367 }
1368
1369
1370 /* JVM_ConstantPoolGetSize */
1371
1372 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
1373 {
1374         classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1375
1376         TRACEJVMCALLS(("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool));
1377
1378         c = LLNI_classinfo_unwrap(jcpool);
1379
1380         return c->cpcount;
1381 }
1382
1383
1384 /* JVM_ConstantPoolGetClassAt */
1385
1386 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1387 {
1388         constant_classref *ref;    /* classref to the class at constant pool index 'index' */
1389         classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
1390         classinfo         *result; /* classinfo of the class at constant pool index 'index' */
1391
1392         TRACEJVMCALLS(("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index));
1393
1394         c = LLNI_classinfo_unwrap(jcpool);
1395
1396         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1397
1398         if (ref == NULL) {
1399                 exceptions_throw_illegalargumentexception();
1400                 return NULL;
1401         }
1402
1403         result = resolve_classref_eager(ref);
1404
1405         return (jclass) LLNI_classinfo_wrap(result);
1406 }
1407
1408
1409 /* JVM_ConstantPoolGetClassAtIfLoaded */
1410
1411 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1412 {
1413         constant_classref *ref;    /* classref to the class at constant pool index 'index' */
1414         classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
1415         classinfo         *result; /* classinfo of the class at constant pool index 'index' */
1416
1417         TRACEJVMCALLS(("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index));
1418
1419         c = LLNI_classinfo_unwrap(jcpool);
1420
1421         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1422
1423         if (ref == NULL) {
1424                 exceptions_throw_illegalargumentexception();
1425                 return NULL;
1426         }
1427         
1428         if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result)) {
1429                 return NULL;
1430         }
1431
1432         if ((result == NULL) || !(result->state & CLASS_LOADED)) {
1433                 return NULL;
1434         }
1435         
1436         return (jclass) LLNI_classinfo_wrap(result);
1437 }
1438
1439
1440 /* JVM_ConstantPoolGetMethodAt */
1441
1442 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1443 {
1444         constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1445         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1446         
1447         TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index));
1448         
1449         cls = LLNI_classinfo_unwrap(jcpool);
1450         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1451         
1452         if (ref == NULL) {
1453                 exceptions_throw_illegalargumentexception();
1454                 return NULL;
1455         }
1456
1457         /* XXX: is that right? or do I have to use resolve_method_*? */
1458         return (jobject)reflect_method_new(ref->p.method);
1459 }
1460
1461
1462 /* JVM_ConstantPoolGetMethodAtIfLoaded */
1463
1464 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1465 {
1466         constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1467         classinfo *c = NULL;  /* resolved declaring class of the method */
1468         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1469
1470         TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1471
1472         cls = LLNI_classinfo_unwrap(jcpool);
1473         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1474
1475         if (ref == NULL) {
1476                 exceptions_throw_illegalargumentexception();
1477                 return NULL;
1478         }
1479
1480         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1481                 return NULL;
1482         }
1483
1484         if (c == NULL || !(c->state & CLASS_LOADED)) {
1485                 return NULL;
1486         }
1487
1488         return (jobject)reflect_method_new(ref->p.method);
1489 }
1490
1491
1492 /* JVM_ConstantPoolGetFieldAt */
1493
1494 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1495 {
1496         constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1497         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1498         
1499         TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index));
1500
1501         cls = LLNI_classinfo_unwrap(jcpool);
1502         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1503
1504         if (ref == NULL) {
1505                 exceptions_throw_illegalargumentexception();
1506                 return NULL;
1507         }
1508
1509         return (jobject)reflect_field_new(ref->p.field);
1510 }
1511
1512
1513 /* JVM_ConstantPoolGetFieldAtIfLoaded */
1514
1515 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1516 {
1517         constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1518         classinfo *c;         /* resolved declaring class for the field */
1519         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1520
1521         TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1522
1523         cls = LLNI_classinfo_unwrap(jcpool);
1524         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1525
1526         if (ref == NULL) {
1527                 exceptions_throw_illegalargumentexception();
1528                 return NULL;
1529         }
1530
1531         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1532                 return NULL;
1533         }
1534
1535         if (c == NULL || !(c->state & CLASS_LOADED)) {
1536                 return NULL;
1537         }
1538
1539         return (jobject)reflect_field_new(ref->p.field);
1540 }
1541
1542
1543 /* JVM_ConstantPoolGetMemberRefInfoAt */
1544
1545 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1546 {
1547         log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
1548
1549         /* TODO: implement. (this is yet unused be OpenJDK but, so very low priority) */
1550
1551         return NULL;
1552 }
1553
1554
1555 /* JVM_ConstantPoolGetIntAt */
1556
1557 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1558 {
1559         constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
1560         classinfo *cls;        /* classinfo of the class for which 'this' is the constant pool */
1561
1562         TRACEJVMCALLS(("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index));
1563
1564         cls = LLNI_classinfo_unwrap(jcpool);
1565         ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
1566
1567         if (ref == NULL) {
1568                 exceptions_throw_illegalargumentexception();
1569                 return 0;
1570         }
1571
1572         return ref->value;
1573 }
1574
1575
1576 /* JVM_ConstantPoolGetLongAt */
1577
1578 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1579 {
1580         constant_long *ref; /* reference to the long value in constant pool at index 'index' */
1581         classinfo *cls;     /* classinfo of the class for which 'this' is the constant pool */
1582
1583         TRACEJVMCALLS(("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index));
1584
1585         cls = LLNI_classinfo_unwrap(jcpool);
1586         ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
1587
1588         if (ref == NULL) {
1589                 exceptions_throw_illegalargumentexception();
1590                 return 0;
1591         }
1592
1593         return ref->value;
1594 }
1595
1596
1597 /* JVM_ConstantPoolGetFloatAt */
1598
1599 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1600 {
1601         constant_float *ref; /* reference to the float value in constant pool at index 'index' */
1602         classinfo *cls;      /* classinfo of the class for which 'this' is the constant pool */
1603
1604         TRACEJVMCALLS(("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index));
1605
1606         cls = LLNI_classinfo_unwrap(jcpool);
1607         ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
1608
1609         if (ref == NULL) {
1610                 exceptions_throw_illegalargumentexception();
1611                 return 0;
1612         }
1613
1614         return ref->value;
1615 }
1616
1617
1618 /* JVM_ConstantPoolGetDoubleAt */
1619
1620 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1621 {
1622         constant_double *ref; /* reference to the double value in constant pool at index 'index' */
1623         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1624
1625         TRACEJVMCALLS(("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index));
1626
1627         cls = LLNI_classinfo_unwrap(jcpool);
1628         ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
1629
1630         if (ref == NULL) {
1631                 exceptions_throw_illegalargumentexception();
1632                 return 0;
1633         }
1634
1635         return ref->value;
1636 }
1637
1638
1639 /* JVM_ConstantPoolGetStringAt */
1640
1641 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1642 {
1643         utf *ref;       /* utf object for the string in constant pool at index 'index' */
1644         classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1645
1646         TRACEJVMCALLS(("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index));
1647         
1648         cls = LLNI_classinfo_unwrap(jcpool);
1649         ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
1650
1651         if (ref == NULL) {
1652                 exceptions_throw_illegalargumentexception();
1653                 return NULL;
1654         }
1655
1656         /* XXX: I hope literalstring_new is the right Function. */
1657         return (jstring)literalstring_new(ref);
1658 }
1659
1660
1661 /* JVM_ConstantPoolGetUTF8At */
1662
1663 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1664 {
1665         utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
1666         classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1667
1668         TRACEJVMCALLS(("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index));
1669
1670         cls = LLNI_classinfo_unwrap(jcpool);
1671         ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
1672
1673         if (ref == NULL) {
1674                 exceptions_throw_illegalargumentexception();
1675                 return NULL;
1676         }
1677
1678         /* XXX: I hope literalstring_new is the right Function. */
1679         return (jstring)literalstring_new(ref);
1680 }
1681
1682
1683 /* JVM_DesiredAssertionStatus */
1684
1685 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
1686 {
1687 #if defined(ENABLE_ASSERTION)
1688         assertion_name_t  *item;
1689         classinfo         *c;
1690         jboolean           status;
1691         utf               *name;
1692
1693         TRACEJVMCALLS(("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls));
1694
1695         c = LLNI_classinfo_unwrap(cls);
1696
1697         if (c->classloader == NULL) {
1698                 status = (jboolean)assertion_system_enabled;
1699         }
1700         else {
1701                 status = (jboolean)assertion_user_enabled;
1702         }
1703
1704         if (list_assertion_names != NULL) {
1705                 item = (assertion_name_t *)list_first(list_assertion_names);
1706                 while (item != NULL) {
1707                         name = utf_new_char(item->name);
1708                         if (name == c->packagename) {
1709                                 status = (jboolean)item->enabled;
1710                         }
1711                         else if (name == c->name) {
1712                                 status = (jboolean)item->enabled;
1713                         }
1714
1715                         item = (assertion_name_t *)list_next(list_assertion_names, item);
1716                 }
1717         }
1718
1719         return status;
1720 #else
1721         return (jboolean)false;
1722 #endif
1723 }
1724
1725
1726 /* JVM_AssertionStatusDirectives */
1727
1728 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
1729 {
1730         classinfo                             *c;
1731         java_lang_AssertionStatusDirectives   *o;
1732         java_handle_objectarray_t             *classes;
1733         java_handle_objectarray_t             *packages;
1734         java_booleanarray_t                   *classEnabled;
1735         java_booleanarray_t                   *packageEnabled;
1736 #if defined(ENABLE_ASSERTION)
1737         assertion_name_t                      *item;
1738         java_handle_t                         *js;
1739         s4                                     i, j;
1740 #endif
1741
1742         TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
1743
1744         c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
1745
1746         if (c == NULL)
1747                 return NULL;
1748
1749         o = (java_lang_AssertionStatusDirectives *) builtin_new(c);
1750
1751         if (o == NULL)
1752                 return NULL;
1753
1754 #if defined(ENABLE_ASSERTION)
1755         classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
1756 #else
1757         classes = builtin_anewarray(0, class_java_lang_Object);
1758 #endif
1759         if (classes == NULL)
1760                 return NULL;
1761
1762 #if defined(ENABLE_ASSERTION)
1763         packages = builtin_anewarray(assertion_package_count, class_java_lang_Object);
1764 #else
1765         packages = builtin_anewarray(0, class_java_lang_Object);
1766 #endif
1767         if (packages == NULL)
1768                 return NULL;
1769         
1770 #if defined(ENABLE_ASSERTION)
1771         classEnabled = builtin_newarray_boolean(assertion_class_count);
1772 #else
1773         classEnabled = builtin_newarray_boolean(0);
1774 #endif
1775         if (classEnabled == NULL)
1776                 return NULL;
1777
1778 #if defined(ENABLE_ASSERTION)
1779         packageEnabled = builtin_newarray_boolean(assertion_package_count);
1780 #else
1781         packageEnabled = builtin_newarray_boolean(0);
1782 #endif
1783         if (packageEnabled == NULL)
1784                 return NULL;
1785
1786 #if defined(ENABLE_ASSERTION)
1787         /* initialize arrays */
1788
1789         if (list_assertion_names != NULL) {
1790                 i = 0;
1791                 j = 0;
1792                 
1793                 item = (assertion_name_t *)list_first(list_assertion_names);
1794                 while (item != NULL) {
1795                         js = javastring_new_from_ascii(item->name);
1796                         if (js == NULL) {
1797                                 return NULL;
1798                         }
1799
1800                         if (item->package == false) {
1801                                 classes->data[i] = js;
1802                                 classEnabled->data[i] = (jboolean) item->enabled;
1803                                 i += 1;
1804                         }
1805                         else {
1806                                 packages->data[j] = js;
1807                                 packageEnabled->data[j] = (jboolean) item->enabled;
1808                                 j += 1;
1809                         }
1810
1811                         item = (assertion_name_t *)list_next(list_assertion_names, item);
1812                 }
1813         }
1814 #endif
1815
1816         /* set instance fields */
1817
1818         o->classes  = classes;
1819         o->packages = packages;
1820         o->classEnabled = classEnabled;
1821         o->packageEnabled = packageEnabled;
1822
1823         return (jobject) o;
1824 }
1825
1826
1827 /* JVM_GetClassNameUTF */
1828
1829 const char *JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
1830 {
1831         log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
1832
1833         return NULL;
1834 }
1835
1836
1837 /* JVM_GetClassCPTypes */
1838
1839 void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
1840 {
1841         log_println("JVM_GetClassCPTypes: IMPLEMENT ME!");
1842 }
1843
1844
1845 /* JVM_GetClassCPEntriesCount */
1846
1847 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
1848 {
1849         log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
1850
1851         return 0;
1852 }
1853
1854
1855 /* JVM_GetClassFieldsCount */
1856
1857 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
1858 {
1859         log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
1860
1861         return 0;
1862 }
1863
1864
1865 /* JVM_GetClassMethodsCount */
1866
1867 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
1868 {
1869         log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
1870
1871         return 0;
1872 }
1873
1874
1875 /* JVM_GetMethodIxExceptionIndexes */
1876
1877 void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)
1878 {
1879         log_println("JVM_GetMethodIxExceptionIndexes: IMPLEMENT ME!");
1880 }
1881
1882
1883 /* JVM_GetMethodIxExceptionsCount */
1884
1885 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
1886 {
1887         log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
1888
1889         return 0;
1890 }
1891
1892
1893 /* JVM_GetMethodIxByteCode */
1894
1895 void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)
1896 {
1897         log_println("JVM_GetMethodIxByteCode: IMPLEMENT ME!");
1898 }
1899
1900
1901 /* JVM_GetMethodIxByteCodeLength */
1902
1903 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
1904 {
1905         log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
1906
1907         return 0;
1908 }
1909
1910
1911 /* JVM_GetMethodIxExceptionTableEntry */
1912
1913 void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)
1914 {
1915         log_println("JVM_GetMethodIxExceptionTableEntry: IMPLEMENT ME!");
1916 }
1917
1918
1919 /* JVM_GetMethodIxExceptionTableLength */
1920
1921 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
1922 {
1923         log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
1924
1925         return 0;
1926 }
1927
1928
1929 /* JVM_GetMethodIxModifiers */
1930
1931 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
1932 {
1933         log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
1934
1935         return 0;
1936 }
1937
1938
1939 /* JVM_GetFieldIxModifiers */
1940
1941 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
1942 {
1943         log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
1944
1945         return 0;
1946 }
1947
1948
1949 /* JVM_GetMethodIxLocalsCount */
1950
1951 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
1952 {
1953         log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
1954
1955         return 0;
1956 }
1957
1958
1959 /* JVM_GetMethodIxArgsSize */
1960
1961 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
1962 {
1963         log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
1964
1965         return 0;
1966 }
1967
1968
1969 /* JVM_GetMethodIxMaxStack */
1970
1971 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
1972 {
1973         log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
1974
1975         return 0;
1976 }
1977
1978
1979 /* JVM_IsConstructorIx */
1980
1981 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
1982 {
1983         log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
1984
1985         return 0;
1986 }
1987
1988
1989 /* JVM_GetMethodIxNameUTF */
1990
1991 const char *JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
1992 {
1993         log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
1994
1995         return NULL;
1996 }
1997
1998
1999 /* JVM_GetMethodIxSignatureUTF */
2000
2001 const char *JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
2002 {
2003         log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
2004
2005         return NULL;
2006 }
2007
2008
2009 /* JVM_GetCPFieldNameUTF */
2010
2011 const char *JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2012 {
2013         log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
2014
2015         return NULL;
2016 }
2017
2018
2019 /* JVM_GetCPMethodNameUTF */
2020
2021 const char *JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2022 {
2023         log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
2024
2025         return NULL;
2026 }
2027
2028
2029 /* JVM_GetCPMethodSignatureUTF */
2030
2031 const char *JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
2032 {
2033         log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
2034
2035         return NULL;
2036 }
2037
2038
2039 /* JVM_GetCPFieldSignatureUTF */
2040
2041 const char *JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
2042 {
2043         log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
2044
2045         return NULL;
2046 }
2047
2048
2049 /* JVM_GetCPClassNameUTF */
2050
2051 const char *JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2052 {
2053         log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
2054
2055         return NULL;
2056 }
2057
2058
2059 /* JVM_GetCPFieldClassNameUTF */
2060
2061 const char *JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2062 {
2063         log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
2064
2065         return NULL;
2066 }
2067
2068
2069 /* JVM_GetCPMethodClassNameUTF */
2070
2071 const char *JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2072 {
2073         log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
2074
2075         return NULL;
2076 }
2077
2078
2079 /* JVM_GetCPFieldModifiers */
2080
2081 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
2082 {
2083         log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
2084
2085         return 0;
2086 }
2087
2088
2089 /* JVM_GetCPMethodModifiers */
2090
2091 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
2092 {
2093         log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
2094
2095         return 0;
2096 }
2097
2098
2099 /* JVM_ReleaseUTF */
2100
2101 void JVM_ReleaseUTF(const char *utf)
2102 {
2103         log_println("JVM_ReleaseUTF: IMPLEMENT ME!");
2104 }
2105
2106
2107 /* JVM_IsSameClassPackage */
2108
2109 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
2110 {
2111         log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
2112
2113         return 0;
2114 }
2115
2116
2117 /* JVM_Open */
2118
2119 /* Taken from: hotspot/src/share/vm/prims/jvm.h */
2120
2121 /*
2122  * JVM I/O error codes
2123  */
2124 #define JVM_EEXIST       -100
2125
2126 jint JVM_Open(const char *fname, jint flags, jint mode)
2127 {
2128         int result;
2129
2130         TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
2131
2132         result = hpi_file->Open(fname, flags, mode);
2133
2134         if (result >= 0) {
2135                 return result;
2136         }
2137         else {
2138                 switch (errno) {
2139                 case EEXIST:
2140                         return JVM_EEXIST;
2141                 default:
2142                         return -1;
2143                 }
2144         }
2145 }
2146
2147
2148 /* JVM_Close */
2149
2150 jint JVM_Close(jint fd)
2151 {
2152         TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
2153
2154         return hpi_file->Close(fd);
2155 }
2156
2157
2158 /* JVM_Read */
2159
2160 jint JVM_Read(jint fd, char *buf, jint nbytes)
2161 {
2162         TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
2163
2164         return (jint) hpi_file->Read(fd, buf, nbytes);
2165 }
2166
2167
2168 /* JVM_Write */
2169
2170 jint JVM_Write(jint fd, char *buf, jint nbytes)
2171 {
2172         TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
2173
2174         return (jint) hpi_file->Write(fd, buf, nbytes);
2175 }
2176
2177
2178 /* JVM_Available */
2179
2180 jint JVM_Available(jint fd, jlong *pbytes)
2181 {
2182         TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
2183
2184         return hpi_file->Available(fd, pbytes);
2185 }
2186
2187
2188 /* JVM_Lseek */
2189
2190 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
2191 {
2192         TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
2193
2194         return hpi_file->Seek(fd, (off_t) offset, whence);
2195 }
2196
2197
2198 /* JVM_SetLength */
2199
2200 jint JVM_SetLength(jint fd, jlong length)
2201 {
2202         TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
2203
2204         return hpi_file->SetLength(fd, length);
2205 }
2206
2207
2208 /* JVM_Sync */
2209
2210 jint JVM_Sync(jint fd)
2211 {
2212         TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
2213
2214         return hpi_file->Sync(fd);
2215 }
2216
2217
2218 /* JVM_StartThread */
2219
2220 void JVM_StartThread(JNIEnv* env, jobject jthread)
2221 {
2222         TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
2223
2224         threads_thread_start((java_handle_t *) jthread);
2225 }
2226
2227
2228 /* JVM_StopThread */
2229
2230 void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
2231 {
2232         log_println("JVM_StopThread: IMPLEMENT ME!");
2233 }
2234
2235
2236 /* JVM_IsThreadAlive */
2237
2238 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
2239 {
2240         java_handle_t *h;
2241         threadobject  *t;
2242         bool           result;
2243
2244         TRACEJVMCALLS(("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread));
2245
2246         h = (java_handle_t *) jthread;
2247         t = thread_get_thread(h);
2248
2249         /* The threadobject is null when a thread is created in Java. The
2250            priority is set later during startup. */
2251
2252         if (t == NULL)
2253                 return 0;
2254
2255         result = threads_thread_is_alive(t);
2256
2257         return result;
2258 }
2259
2260
2261 /* JVM_SuspendThread */
2262
2263 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
2264 {
2265         log_println("JVM_SuspendThread: IMPLEMENT ME!");
2266 }
2267
2268
2269 /* JVM_ResumeThread */
2270
2271 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
2272 {
2273         log_println("JVM_ResumeThread: IMPLEMENT ME!");
2274 }
2275
2276
2277 /* JVM_SetThreadPriority */
2278
2279 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
2280 {
2281         java_handle_t *h;
2282         threadobject  *t;
2283
2284         TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
2285
2286         h = (java_handle_t *) jthread;
2287         t = thread_get_thread(h);
2288
2289         /* The threadobject is null when a thread is created in Java. The
2290            priority is set later during startup. */
2291
2292         if (t == NULL)
2293                 return;
2294
2295         threads_set_thread_priority(t->tid, prio);
2296 }
2297
2298
2299 /* JVM_Yield */
2300
2301 void JVM_Yield(JNIEnv *env, jclass threadClass)
2302 {
2303         TRACEJVMCALLS(("JVM_Yield(env=%p, threadClass=%p)", env, threadClass));
2304
2305         threads_yield();
2306 }
2307
2308
2309 /* JVM_Sleep */
2310
2311 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
2312 {
2313         TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
2314
2315         threads_sleep(millis, 0);
2316 }
2317
2318
2319 /* JVM_CurrentThread */
2320
2321 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
2322 {
2323         java_object_t *o;
2324
2325         TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
2326
2327         o = threads_get_current_object();
2328
2329         return (jobject) o;
2330 }
2331
2332
2333 /* JVM_CountStackFrames */
2334
2335 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
2336 {
2337         log_println("JVM_CountStackFrames: IMPLEMENT ME!");
2338
2339         return 0;
2340 }
2341
2342
2343 /* JVM_Interrupt */
2344
2345 void JVM_Interrupt(JNIEnv* env, jobject jthread)
2346 {
2347         java_handle_t *h;
2348         threadobject  *t;
2349
2350         TRACEJVMCALLS(("JVM_Interrupt(env=%p, jthread=%p)", env, jthread));
2351
2352         h = (java_handle_t *) jthread;
2353         t = thread_get_thread(h);
2354
2355         if (t == NULL)
2356                 return;
2357
2358         threads_thread_interrupt(t);
2359 }
2360
2361
2362 /* JVM_IsInterrupted */
2363
2364 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2365 {
2366         java_handle_t *h;
2367         threadobject  *t;
2368
2369         TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
2370
2371         h = (java_handle_t *) jthread;
2372         t = thread_get_thread(h);
2373
2374         /* XXX do something with clear_interrupted */
2375
2376         return threads_thread_has_been_interrupted(t);
2377 }
2378
2379
2380 /* JVM_HoldsLock */
2381
2382 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2383 {
2384         java_handle_t *h;
2385         bool           result;
2386
2387         TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
2388
2389         h = (java_handle_t *) obj;
2390
2391         if (h == NULL) {
2392                 exceptions_throw_nullpointerexception();
2393                 return JNI_FALSE;
2394         }
2395
2396         result = lock_is_held_by_current_thread(h);
2397
2398         return result;
2399 }
2400
2401
2402 /* JVM_DumpAllStacks */
2403
2404 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2405 {
2406         log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2407 }
2408
2409
2410 /* JVM_CurrentLoadedClass */
2411
2412 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2413 {
2414         log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2415
2416         return NULL;
2417 }
2418
2419
2420 /* JVM_CurrentClassLoader */
2421
2422 jobject JVM_CurrentClassLoader(JNIEnv *env)
2423 {
2424     /* XXX if a method in a class in a trusted loader is in a
2425            doPrivileged, return NULL */
2426
2427         log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2428
2429         return NULL;
2430 }
2431
2432
2433 /* JVM_GetClassContext */
2434
2435 jobjectArray JVM_GetClassContext(JNIEnv *env)
2436 {
2437         TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
2438
2439         return (jobjectArray) stacktrace_getClassContext();
2440 }
2441
2442
2443 /* JVM_ClassDepth */
2444
2445 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2446 {
2447         log_println("JVM_ClassDepth: IMPLEMENT ME!");
2448
2449         return 0;
2450 }
2451
2452
2453 /* JVM_ClassLoaderDepth */
2454
2455 jint JVM_ClassLoaderDepth(JNIEnv *env)
2456 {
2457         log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2458
2459         return 0;
2460 }
2461
2462
2463 /* JVM_GetSystemPackage */
2464
2465 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2466 {
2467         java_handle_t *s;
2468         utf *u;
2469         utf *result;
2470
2471         TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
2472
2473 /*      s = package_find(name); */
2474         u = javastring_toutf((java_handle_t *) name, false);
2475
2476         result = package_find(u);
2477
2478         if (result != NULL)
2479                 s = javastring_new(result);
2480         else
2481                 s = NULL;
2482
2483         return (jstring) s;
2484 }
2485
2486
2487 /* JVM_GetSystemPackages */
2488
2489 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2490 {
2491         log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2492
2493         return NULL;
2494 }
2495
2496
2497 /* JVM_AllocateNewObject */
2498
2499 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2500 {
2501         log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2502
2503         return NULL;
2504 }
2505
2506
2507 /* JVM_AllocateNewArray */
2508
2509 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2510 {
2511         log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2512
2513         return NULL;
2514 }
2515
2516
2517 /* JVM_LatestUserDefinedLoader */
2518
2519 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2520 {
2521         classloader *cl;
2522
2523         TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
2524
2525         cl = stacktrace_first_nonnull_classloader();
2526
2527         return (jobject) cl;
2528 }
2529
2530
2531 /* JVM_LoadClass0 */
2532
2533 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2534 {
2535         log_println("JVM_LoadClass0: IMPLEMENT ME!");
2536
2537         return NULL;
2538 }
2539
2540
2541 /* JVM_GetArrayLength */
2542
2543 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2544 {
2545         java_handle_t *a;
2546
2547         TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
2548
2549         a = (java_handle_t *) arr;
2550
2551         return array_length_get(a);
2552 }
2553
2554
2555 /* JVM_GetArrayElement */
2556
2557 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2558 {
2559         java_handle_t *a;
2560         java_handle_t *o;
2561
2562         TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
2563
2564         a = (java_handle_t *) arr;
2565
2566 /*      if (!class_is_array(a->objheader.vftbl->class)) { */
2567 /*              exceptions_throw_illegalargumentexception(); */
2568 /*              return NULL; */
2569 /*      } */
2570
2571         o = array_element_get(a, index);
2572
2573         return (jobject) o;
2574 }
2575
2576
2577 /* JVM_GetPrimitiveArrayElement */
2578
2579 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2580 {
2581         jvalue jv;
2582
2583         log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2584
2585         jv.l = NULL;
2586
2587         return jv;
2588 }
2589
2590
2591 /* JVM_SetArrayElement */
2592
2593 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2594 {
2595         java_handle_t *a;
2596         java_handle_t *value;
2597
2598         TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
2599
2600         a     = (java_handle_t *) arr;
2601         value = (java_handle_t *) val;
2602
2603         array_element_set(a, index, value);
2604 }
2605
2606
2607 /* JVM_SetPrimitiveArrayElement */
2608
2609 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2610 {
2611         log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2612 }
2613
2614
2615 /* JVM_NewArray */
2616
2617 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2618 {
2619         classinfo                 *c;
2620         classinfo                 *pc;
2621         java_handle_t             *a;
2622         java_handle_objectarray_t *oa;
2623
2624         TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
2625
2626         if (eltClass == NULL) {
2627                 exceptions_throw_nullpointerexception();
2628                 return NULL;
2629         }
2630
2631         /* NegativeArraySizeException is checked in builtin_newarray. */
2632
2633         c = LLNI_classinfo_unwrap(eltClass);
2634
2635         /* Create primitive or object array. */
2636
2637         if (class_is_primitive(c)) {
2638                 pc = primitive_arrayclass_get_by_name(c->name);
2639
2640                 /* void arrays are not allowed. */
2641
2642                 if (pc == NULL) {
2643                         exceptions_throw_illegalargumentexception();
2644                         return NULL;
2645                 }
2646
2647                 a = builtin_newarray(length, pc);
2648
2649                 return (jobject) a;
2650         }
2651         else {
2652                 oa = builtin_anewarray(length, c);
2653
2654                 return (jobject) oa;
2655         }
2656 }
2657
2658
2659 /* JVM_NewMultiArray */
2660
2661 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2662 {
2663         classinfo                 *c;
2664         java_handle_intarray_t    *ia;
2665         int32_t                    length;
2666         long                      *dims;
2667         int32_t                    value;
2668         int32_t                    i;
2669         classinfo                 *ac;
2670         java_handle_objectarray_t *a;
2671
2672         TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
2673
2674         if (eltClass == NULL) {
2675                 exceptions_throw_nullpointerexception();
2676                 return NULL;
2677         }
2678
2679         /* NegativeArraySizeException is checked in builtin_newarray. */
2680
2681         c = LLNI_classinfo_unwrap(eltClass);
2682
2683         ia = (java_handle_intarray_t *) dim;
2684
2685         length = array_length_get((java_handle_t *) ia);
2686
2687         /* We check here for exceptions thrown in array_length_get,
2688            otherwise these exceptions get overwritten by the following
2689            IllegalArgumentException. */
2690
2691         if (length < 0)
2692                 return NULL;
2693
2694         if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
2695                 exceptions_throw_illegalargumentexception();
2696                 return NULL;
2697         }
2698
2699         /* XXX This is just a quick hack to get it working. */
2700
2701         dims = MNEW(long, length);
2702
2703         for (i = 0; i < length; i++) {
2704                 value = LLNI_array_direct(ia, i);
2705                 dims[i] = (long) value;
2706         }
2707
2708         /* Create an array-class if necessary. */
2709
2710         if (class_is_primitive(c))
2711                 ac = primitive_arrayclass_get_by_name(c->name);
2712         else
2713                 ac = class_array_of(c, true);
2714
2715         if (ac == NULL)
2716                 return NULL;
2717
2718         a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
2719
2720         return (jobject) a;
2721 }
2722
2723
2724 /* JVM_InitializeSocketLibrary */
2725
2726 jint JVM_InitializeSocketLibrary()
2727 {
2728         TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
2729
2730         return hpi_initialize_socket_library();
2731 }
2732
2733
2734 /* JVM_Socket */
2735
2736 jint JVM_Socket(jint domain, jint type, jint protocol)
2737 {
2738         TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
2739
2740         return system_socket(domain, type, protocol);
2741 }
2742
2743
2744 /* JVM_SocketClose */
2745
2746 jint JVM_SocketClose(jint fd)
2747 {
2748         TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
2749
2750         return system_close(fd);
2751 }
2752
2753
2754 /* JVM_SocketShutdown */
2755
2756 jint JVM_SocketShutdown(jint fd, jint howto)
2757 {
2758         TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
2759
2760         return system_shutdown(fd, howto);
2761 }
2762
2763
2764 /* JVM_Recv */
2765
2766 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2767 {
2768         log_println("JVM_Recv: IMPLEMENT ME!");
2769
2770         return 0;
2771 }
2772
2773
2774 /* JVM_Send */
2775
2776 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2777 {
2778         log_println("JVM_Send: IMPLEMENT ME!");
2779
2780         return 0;
2781 }
2782
2783
2784 /* JVM_Timeout */
2785
2786 jint JVM_Timeout(int fd, long timeout)
2787 {
2788         log_println("JVM_Timeout: IMPLEMENT ME!");
2789
2790         return 0;
2791 }
2792
2793
2794 /* JVM_Listen */
2795
2796 jint JVM_Listen(jint fd, jint count)
2797 {
2798         TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
2799
2800         return system_listen(fd, count);
2801 }
2802
2803
2804 /* JVM_Connect */
2805
2806 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2807 {
2808         TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
2809
2810         return system_connect(fd, him, len);
2811 }
2812
2813
2814 /* JVM_Bind */
2815
2816 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2817 {
2818         log_println("JVM_Bind: IMPLEMENT ME!");
2819
2820         return 0;
2821 }
2822
2823
2824 /* JVM_Accept */
2825
2826 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2827 {
2828         TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
2829
2830         return system_accept(fd, him, (socklen_t *) len);
2831 }
2832
2833
2834 /* JVM_RecvFrom */
2835
2836 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2837 {
2838         log_println("JVM_RecvFrom: IMPLEMENT ME!");
2839
2840         return 0;
2841 }
2842
2843
2844 /* JVM_GetSockName */
2845
2846 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2847 {
2848         TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
2849
2850         return system_getsockname(fd, him, (socklen_t *) len);
2851 }
2852
2853
2854 /* JVM_SendTo */
2855
2856 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2857 {
2858         log_println("JVM_SendTo: IMPLEMENT ME!");
2859
2860         return 0;
2861 }
2862
2863
2864 /* JVM_SocketAvailable */
2865
2866 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2867 {
2868 #if defined(FIONREAD)
2869         int bytes;
2870         int result;
2871
2872         TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
2873
2874         *pbytes = 0;
2875
2876         result = ioctl(fd, FIONREAD, &bytes);
2877
2878         if (result < 0)
2879                 return 0;
2880
2881         *pbytes = bytes;
2882
2883         return 1;
2884 #else
2885 # error FIONREAD not defined
2886 #endif
2887 }
2888
2889
2890 /* JVM_GetSockOpt */
2891
2892 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2893 {
2894         TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
2895
2896         return system_getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
2897 }
2898
2899
2900 /* JVM_SetSockOpt */
2901
2902 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2903 {
2904         TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
2905
2906         return system_setsockopt(fd, level, optname, optval, optlen);
2907 }
2908
2909
2910 /* JVM_GetHostName */
2911
2912 int JVM_GetHostName(char *name, int namelen)
2913 {
2914         TRACEJVMCALLS(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
2915
2916         return system_gethostname(name, namelen);
2917 }
2918
2919
2920 /* JVM_GetHostByAddr */
2921
2922 struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
2923 {
2924         log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2925
2926         return NULL;
2927 }
2928
2929
2930 /* JVM_GetHostByName */
2931
2932 struct hostent *JVM_GetHostByName(char* name)
2933 {
2934         log_println("JVM_GetHostByName: IMPLEMENT ME!");
2935
2936         return NULL;
2937 }
2938
2939
2940 /* JVM_GetProtoByName */
2941
2942 struct protoent *JVM_GetProtoByName(char* name)
2943 {
2944         log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2945
2946         return NULL;
2947 }
2948
2949
2950 /* JVM_LoadLibrary */
2951
2952 void *JVM_LoadLibrary(const char *name)
2953 {
2954         utf *u;
2955
2956         TRACEJVMCALLS(("JVM_LoadLibrary(name=%s)", name));
2957
2958         u = utf_new_char(name);
2959
2960         return native_library_open(u);
2961 }
2962
2963
2964 /* JVM_UnloadLibrary */
2965
2966 void JVM_UnloadLibrary(void* handle)
2967 {
2968         TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
2969
2970         native_library_close(handle);
2971 }
2972
2973
2974 /* JVM_FindLibraryEntry */
2975
2976 void *JVM_FindLibraryEntry(void *handle, const char *name)
2977 {
2978         lt_ptr symbol;
2979
2980         TRACEJVMCALLS(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
2981
2982         symbol = lt_dlsym(handle, name);
2983
2984         return symbol;
2985 }
2986
2987
2988 /* JVM_IsNaN */
2989
2990 jboolean JVM_IsNaN(jdouble a)
2991 {
2992         log_println("JVM_IsNaN: IMPLEMENT ME!");
2993
2994         return 0;
2995 }
2996
2997
2998 /* JVM_IsSupportedJNIVersion */
2999
3000 jboolean JVM_IsSupportedJNIVersion(jint version)
3001 {
3002         TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
3003
3004         return jni_version_check(version);
3005 }
3006
3007
3008 /* JVM_InternString */
3009
3010 jstring JVM_InternString(JNIEnv *env, jstring str)
3011 {
3012         TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
3013
3014         return (jstring) javastring_intern((java_handle_t *) str);
3015 }
3016
3017
3018 /* JVM_RawMonitorCreate */
3019
3020 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
3021 {
3022         java_object_t *o;
3023
3024         TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
3025
3026         o = NEW(java_object_t);
3027
3028         lock_init_object_lock(o);
3029
3030         return o;
3031 }
3032
3033
3034 /* JVM_RawMonitorDestroy */
3035
3036 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
3037 {
3038         TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
3039
3040         FREE(mon, java_object_t);
3041 }
3042
3043
3044 /* JVM_RawMonitorEnter */
3045
3046 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
3047 {
3048         TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
3049
3050         (void) lock_monitor_enter((java_object_t *) mon);
3051
3052         return 0;
3053 }
3054
3055
3056 /* JVM_RawMonitorExit */
3057
3058 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
3059 {
3060         TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
3061
3062         (void) lock_monitor_exit((java_object_t *) mon);
3063 }
3064
3065
3066 /* JVM_SetPrimitiveFieldValues */
3067
3068 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3069 {
3070         log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
3071 }
3072
3073
3074 /* JVM_GetPrimitiveFieldValues */
3075
3076 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3077 {
3078         log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
3079 }
3080
3081
3082 /* JVM_AccessVMBooleanFlag */
3083
3084 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
3085 {
3086         log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
3087
3088         return 0;
3089 }
3090
3091
3092 /* JVM_AccessVMIntFlag */
3093
3094 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
3095 {
3096         log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
3097
3098         return 0;
3099 }
3100
3101
3102 /* JVM_VMBreakPoint */
3103
3104 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
3105 {
3106         log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
3107 }
3108
3109
3110 /* JVM_GetClassFields */
3111
3112 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
3113 {
3114         log_println("JVM_GetClassFields: IMPLEMENT ME!");
3115
3116         return NULL;
3117 }
3118
3119
3120 /* JVM_GetClassMethods */
3121
3122 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
3123 {
3124         log_println("JVM_GetClassMethods: IMPLEMENT ME!");
3125
3126         return NULL;
3127 }
3128
3129
3130 /* JVM_GetClassConstructors */
3131
3132 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
3133 {
3134         log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
3135
3136         return NULL;
3137 }
3138
3139
3140 /* JVM_GetClassField */
3141
3142 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
3143 {
3144         log_println("JVM_GetClassField: IMPLEMENT ME!");
3145
3146         return NULL;
3147 }
3148
3149
3150 /* JVM_GetClassMethod */
3151
3152 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
3153 {
3154         log_println("JVM_GetClassMethod: IMPLEMENT ME!");
3155
3156         return NULL;
3157 }
3158
3159
3160 /* JVM_GetClassConstructor */
3161
3162 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
3163 {
3164         log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
3165
3166         return NULL;
3167 }
3168
3169
3170 /* JVM_NewInstance */
3171
3172 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
3173 {
3174         log_println("JVM_NewInstance: IMPLEMENT ME!");
3175
3176         return NULL;
3177 }
3178
3179
3180 /* JVM_GetField */
3181
3182 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
3183 {
3184         log_println("JVM_GetField: IMPLEMENT ME!");
3185
3186         return NULL;
3187 }
3188
3189
3190 /* JVM_GetPrimitiveField */
3191
3192 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
3193 {
3194         jvalue jv;
3195
3196         log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
3197
3198         jv.l = NULL;
3199
3200         return jv;
3201 }
3202
3203
3204 /* JVM_SetField */
3205
3206 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
3207 {
3208         log_println("JVM_SetField: IMPLEMENT ME!");
3209 }
3210
3211
3212 /* JVM_SetPrimitiveField */
3213
3214 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
3215 {
3216         log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
3217 }
3218
3219
3220 /* JVM_InvokeMethod */
3221
3222 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
3223 {
3224         TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
3225
3226         return (jobject) _Jv_java_lang_reflect_Method_invoke((java_lang_reflect_Method *) method, (java_lang_Object *) obj, (java_handle_objectarray_t *) args0);
3227 }
3228
3229
3230 /* JVM_NewInstanceFromConstructor */
3231
3232 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)
3233 {
3234         TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, c, args0));
3235
3236         return (jobject) _Jv_java_lang_reflect_Constructor_newInstance(env, (java_lang_reflect_Constructor *) c, (java_handle_objectarray_t *) args0);
3237 }
3238
3239
3240 /* JVM_SupportsCX8 */
3241
3242 jboolean JVM_SupportsCX8()
3243 {
3244         TRACEJVMCALLS(("JVM_SupportsCX8()"));
3245
3246         /* IMPLEMENT ME */
3247
3248         return 0;
3249 }
3250
3251
3252 /* JVM_CX8Field */
3253
3254 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
3255 {
3256         log_println("JVM_CX8Field: IMPLEMENT ME!");
3257
3258         return 0;
3259 }
3260
3261
3262 /* JVM_GetAllThreads */
3263
3264 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
3265 {
3266         log_println("JVM_GetAllThreads: IMPLEMENT ME!");
3267
3268         return NULL;
3269 }
3270
3271
3272 /* JVM_DumpThreads */
3273
3274 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
3275 {
3276         log_println("JVM_DumpThreads: IMPLEMENT ME!");
3277
3278         return NULL;
3279 }
3280
3281
3282 /* JVM_GetManagement */
3283
3284 void *JVM_GetManagement(jint version)
3285 {
3286         TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
3287
3288         /* TODO We current don't support the management interface. */
3289
3290         return NULL;
3291 }
3292
3293
3294 /* JVM_InitAgentProperties */
3295
3296 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
3297 {
3298         log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
3299
3300         return NULL;
3301 }
3302
3303
3304 /* JVM_GetEnclosingMethodInfo */
3305
3306 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
3307 {
3308         classinfo                 *c;
3309         methodinfo                *m;
3310         java_handle_objectarray_t *oa;
3311
3312         TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
3313
3314         c = LLNI_classinfo_unwrap(ofClass);
3315
3316         if ((c == NULL) || class_is_primitive(c))
3317                 return NULL;
3318
3319         m = class_get_enclosingmethod(c);
3320
3321         if (m == NULL)
3322                 return NULL;
3323
3324         oa = builtin_anewarray(3, class_java_lang_Object);
3325
3326         if (oa == NULL)
3327                 return NULL;
3328
3329         array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->class));
3330         array_objectarray_element_set(oa, 1, javastring_new(m->name));
3331         array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
3332
3333         return (jobjectArray) oa;
3334 }
3335
3336
3337 /* JVM_GetThreadStateValues */
3338
3339 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
3340 {
3341         java_handle_intarray_t *ia;
3342
3343         TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
3344                                   env, javaThreadState));
3345
3346         /* If new thread states are added in future JDK and VM versions,
3347            this should check if the JDK version is compatible with thread
3348            states supported by the VM.  Return NULL if not compatible.
3349         
3350            This function must map the VM java_lang_Thread::ThreadStatus
3351            to the Java thread state that the JDK supports. */
3352
3353         switch (javaThreadState) {
3354     case THREAD_STATE_NEW:
3355                 ia = builtin_newarray_int(1);
3356
3357                 if (ia == NULL)
3358                         return NULL;
3359
3360                 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
3361                 break; 
3362
3363     case THREAD_STATE_RUNNABLE:
3364                 ia = builtin_newarray_int(1);
3365
3366                 if (ia == NULL)
3367                         return NULL;
3368
3369                 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
3370                 break; 
3371
3372     case THREAD_STATE_BLOCKED:
3373                 ia = builtin_newarray_int(1);
3374
3375                 if (ia == NULL)
3376                         return NULL;
3377
3378                 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
3379                 break; 
3380
3381     case THREAD_STATE_WAITING:
3382                 ia = builtin_newarray_int(2);
3383
3384                 if (ia == NULL)
3385                         return NULL;
3386
3387                 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
3388                 /* XXX Implement parked stuff. */
3389 /*              array_intarray_element_set(ia, 1, PARKED); */
3390                 break; 
3391
3392     case THREAD_STATE_TIMED_WAITING:
3393                 ia = builtin_newarray_int(3);
3394
3395                 if (ia == NULL)
3396                         return NULL;
3397
3398                 /* XXX Not sure about that one. */
3399 /*              array_intarray_element_set(ia, 0, SLEEPING); */
3400                 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
3401                 /* XXX Implement parked stuff. */
3402 /*              array_intarray_element_set(ia, 2, PARKED); */
3403                 break; 
3404
3405     case THREAD_STATE_TERMINATED:
3406                 ia = builtin_newarray_int(1);
3407
3408                 if (ia == NULL)
3409                         return NULL;
3410
3411                 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
3412                 break; 
3413
3414     default:
3415                 /* Unknown state - probably incompatible JDK version */
3416                 return NULL;
3417         }
3418
3419         return (jintArray) ia;
3420 }
3421
3422
3423 /* JVM_GetThreadStateNames */
3424
3425 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
3426 {
3427         java_handle_intarray_t    *ia;
3428         java_handle_objectarray_t *oa;
3429         java_object_t             *s;
3430
3431         TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
3432                                   env, javaThreadState, values));
3433
3434         ia = (java_handle_intarray_t *) values;
3435
3436         /* If new thread states are added in future JDK and VM versions,
3437            this should check if the JDK version is compatible with thread
3438            states supported by the VM.  Return NULL if not compatible.
3439         
3440            This function must map the VM java_lang_Thread::ThreadStatus
3441            to the Java thread state that the JDK supports. */
3442
3443         if (values == NULL) {
3444                 exceptions_throw_nullpointerexception();
3445                 return NULL;
3446         }
3447
3448         switch (javaThreadState) {
3449     case THREAD_STATE_NEW:
3450                 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
3451
3452                 oa = builtin_anewarray(1, class_java_lang_String);
3453
3454                 if (oa == NULL)
3455                         return NULL;
3456
3457                 s = javastring_new(utf_new_char("NEW"));
3458
3459                 if (s == NULL)
3460                         return NULL;
3461
3462                 array_objectarray_element_set(oa, 0, s);
3463                 break; 
3464
3465     case THREAD_STATE_RUNNABLE:
3466                 oa = builtin_anewarray(1, class_java_lang_String);
3467
3468                 if (oa == NULL)
3469                         return NULL;
3470
3471                 s = javastring_new(utf_new_char("RUNNABLE"));
3472
3473                 if (s == NULL)
3474                         return NULL;
3475
3476                 array_objectarray_element_set(oa, 0, s);
3477                 break; 
3478
3479     case THREAD_STATE_BLOCKED:
3480                 oa = builtin_anewarray(1, class_java_lang_String);
3481
3482                 if (oa == NULL)
3483                         return NULL;
3484
3485                 s = javastring_new(utf_new_char("BLOCKED"));
3486
3487                 if (s == NULL)
3488                         return NULL;
3489
3490                 array_objectarray_element_set(oa, 0, s);
3491                 break; 
3492
3493     case THREAD_STATE_WAITING:
3494                 oa = builtin_anewarray(2, class_java_lang_String);
3495
3496                 if (oa == NULL)
3497                         return NULL;
3498
3499                 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
3500 /*              s = javastring_new(utf_new_char("WAITING.PARKED")); */
3501
3502                 if (s == NULL)
3503                         return NULL;
3504
3505                 array_objectarray_element_set(oa, 0, s);
3506 /*              array_objectarray_element_set(oa, 1, s); */
3507                 break; 
3508
3509     case THREAD_STATE_TIMED_WAITING:
3510                 oa = builtin_anewarray(3, class_java_lang_String);
3511
3512                 if (oa == NULL)
3513                         return NULL;
3514
3515 /*              s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
3516                 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
3517 /*              s = javastring_new(utf_new_char("TIMED_WAITING.PARKED")); */
3518
3519                 if (s == NULL)
3520                         return NULL;
3521
3522 /*              array_objectarray_element_set(oa, 0, s); */
3523                 array_objectarray_element_set(oa, 0, s);
3524 /*              array_objectarray_element_set(oa, 2, s); */
3525                 break; 
3526
3527     case THREAD_STATE_TERMINATED:
3528                 oa = builtin_anewarray(1, class_java_lang_String);
3529
3530                 if (oa == NULL)
3531                         return NULL;
3532
3533                 s = javastring_new(utf_new_char("TERMINATED"));
3534
3535                 if (s == NULL)
3536                         return NULL;
3537
3538                 array_objectarray_element_set(oa, 0, s);
3539                 break; 
3540
3541         default:
3542                 /* Unknown state - probably incompatible JDK version */
3543                 return NULL;
3544         }
3545
3546         return (jobjectArray) oa;
3547 }
3548
3549
3550 /* JVM_GetVersionInfo */
3551
3552 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3553 {
3554         log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3555 }
3556
3557
3558 /* OS: JVM_RegisterSignal */
3559
3560 void *JVM_RegisterSignal(jint sig, void *handler)
3561 {
3562         functionptr newHandler;
3563
3564         TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
3565
3566         if (handler == (void *) 2)
3567                 newHandler = (functionptr) signal_thread_handler;
3568         else
3569                 newHandler = (functionptr) (uintptr_t) handler;
3570
3571         switch (sig) {
3572     case SIGILL:
3573     case SIGFPE:
3574     case SIGUSR1:
3575     case SIGSEGV:
3576                 /* These signals are already used by the VM. */
3577                 return (void *) -1;
3578
3579     case SIGQUIT:
3580                 /* This signal is used by the VM to dump thread stacks unless
3581                    ReduceSignalUsage is set, in which case the user is allowed
3582                    to set his own _native_ handler for this signal; thus, in
3583                    either case, we do not allow JVM_RegisterSignal to change
3584                    the handler. */
3585                 return (void *) -1;
3586
3587         case SIGHUP:
3588         case SIGINT:
3589         case SIGTERM:
3590                 break;
3591         }
3592
3593         signal_register_signal(sig, newHandler, 0);
3594
3595         /* XXX Should return old handler. */
3596
3597         return (void *) 2;
3598 }
3599
3600
3601 /* OS: JVM_RaiseSignal */
3602
3603 jboolean JVM_RaiseSignal(jint sig)
3604 {
3605         log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3606
3607         return false;
3608 }
3609
3610
3611 /* OS: JVM_FindSignal */
3612
3613 jint JVM_FindSignal(const char *name)
3614 {
3615         TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
3616
3617 #if defined(__LINUX__)
3618         if (strcmp(name, "HUP") == 0)
3619                 return SIGHUP;
3620
3621         if (strcmp(name, "INT") == 0)
3622                 return SIGINT;
3623
3624         if (strcmp(name, "TERM") == 0)
3625                 return SIGTERM;
3626 #else
3627 # error not implemented for this OS
3628 #endif
3629
3630         return -1;
3631 }
3632
3633
3634 /*
3635  * These are local overrides for various environment variables in Emacs.
3636  * Please do not remove this and leave it at the end of the file, where
3637  * Emacs will automagically detect them.
3638  * ---------------------------------------------------------------------
3639  * Local variables:
3640  * mode: c
3641  * indent-tabs-mode: t
3642  * c-basic-offset: 4
3643  * tab-width: 4
3644  * End:
3645  */