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