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