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