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