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