34d66a8549ba002e0733f15fd23bbc8b6e42c097
[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 8395 2007-08-22 13:12:46Z 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         classinfo               *c           = NULL;
1071         java_handle_bytearray_t *annotations = NULL;
1072
1073         TRACEJVMCALLS("JVM_GetClassAnnotations: cls=%p", cls);
1074
1075         if (cls == NULL) {
1076                 exceptions_throw_nullpointerexception();
1077                 return NULL;
1078         }
1079         
1080         c = LLNI_classinfo_unwrap(cls);
1081
1082         /* get annotations: */
1083         annotations = class_get_annotations(c);
1084
1085         return (jbyteArray)annotations;
1086 }
1087
1088
1089 /* JVM_GetFieldAnnotations */
1090
1091 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
1092 {
1093         java_lang_reflect_Field *rf = (java_lang_reflect_Field*)field;
1094         java_handle_bytearray_t *ba = NULL;
1095
1096         TRACEJVMCALLS("JVM_GetFieldAnnotations: field=%p", field);
1097
1098         if (field == NULL) {
1099                 exceptions_throw_nullpointerexception();
1100                 return NULL;
1101         }
1102
1103         LLNI_field_get_ref(rf, annotations, ba);
1104
1105         return (jbyteArray)ba;
1106 }
1107
1108
1109 /* JVM_GetMethodAnnotations */
1110
1111 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
1112 {
1113         java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
1114         java_handle_bytearray_t  *ba = NULL;
1115
1116         TRACEJVMCALLS("JVM_GetMethodAnnotations: method=%p", method);
1117
1118         if (method == NULL) {
1119                 exceptions_throw_nullpointerexception();
1120                 return NULL;
1121         }
1122
1123         LLNI_field_get_ref(rm, annotations, ba);
1124
1125         return (jbyteArray)ba;
1126 }
1127
1128
1129 /* JVM_GetMethodDefaultAnnotationValue */
1130
1131 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
1132 {
1133         java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
1134         java_handle_bytearray_t  *ba = NULL;
1135
1136         TRACEJVMCALLS("JVM_GetMethodDefaultAnnotationValue: method=%p", method);
1137
1138         if (method == NULL) {
1139                 exceptions_throw_nullpointerexception();
1140                 return NULL;
1141         }
1142
1143         LLNI_field_get_ref(rm, annotationDefault, ba);
1144
1145         return (jbyteArray)ba;
1146 }
1147
1148
1149 /* JVM_GetMethodParameterAnnotations */
1150
1151 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
1152 {
1153         java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
1154         java_handle_bytearray_t  *ba = NULL;
1155
1156         TRACEJVMCALLS("JVM_GetMethodParameterAnnotations: method=%p", method);
1157
1158         if (method == NULL) {
1159                 exceptions_throw_nullpointerexception();
1160                 return NULL;
1161         }
1162
1163         LLNI_field_get_ref(rm, parameterAnnotations, ba);
1164
1165         return (jbyteArray)ba;
1166 }
1167
1168
1169 /* JVM_GetClassDeclaredFields */
1170
1171 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1172 {
1173 #if PRINTJVM
1174         log_println("JVM_GetClassDeclaredFields: ofClass=%p, publicOnly=%d", ofClass, publicOnly);
1175 #endif
1176         return (jobjectArray) _Jv_java_lang_Class_getDeclaredFields((java_lang_Class *) ofClass, publicOnly);
1177 }
1178
1179
1180 /* JVM_GetClassDeclaredMethods */
1181
1182 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1183 {
1184 #if PRINTJVM
1185         log_println("JVM_GetClassDeclaredMethods: ofClass=%p, publicOnly=%d", ofClass, publicOnly);
1186 #endif
1187         return (jobjectArray) _Jv_java_lang_Class_getDeclaredMethods((java_lang_Class *) ofClass, publicOnly);
1188 }
1189
1190
1191 /* JVM_GetClassDeclaredConstructors */
1192
1193 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1194 {
1195 #if PRINTJVM
1196         log_println("JVM_GetClassDeclaredConstructors: ofClass=%p, publicOnly=%d", ofClass, publicOnly);
1197 #endif
1198         return (jobjectArray) _Jv_java_lang_Class_getDeclaredConstructors((java_lang_Class *) ofClass, publicOnly);
1199 }
1200
1201
1202 /* JVM_GetClassAccessFlags */
1203
1204 jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
1205 {
1206         classinfo *c;
1207
1208 #if PRINTJVM
1209         log_println("JVM_GetClassAccessFlags: cls=%p", cls);
1210 #endif
1211
1212         c = LLNI_classinfo_unwrap(cls);
1213
1214         return c->flags & ACC_CLASS_REFLECT_MASK;
1215 }
1216
1217
1218 /* JVM_GetClassConstantPool */
1219
1220 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
1221 {
1222 #if defined(ENABLE_ANNOTATIONS)
1223         sun_reflect_ConstantPool *constantPool    = NULL;
1224         java_lang_Object         *constantPoolOop = (java_lang_Object*)cls;
1225         
1226         TRACEJVMCALLS("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls);
1227
1228         constantPool = 
1229                 (sun_reflect_ConstantPool*)native_new_and_init(
1230                         class_sun_reflect_ConstantPool);
1231         
1232         if (constantPool == NULL) {
1233                 /* out of memory */
1234                 return NULL;
1235         }
1236         
1237         LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
1238
1239         return (jobject)constantPool;
1240 #else
1241         log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
1242         return NULL;
1243 #endif
1244 }
1245
1246
1247 /* JVM_ConstantPoolGetSize */
1248
1249 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
1250 {
1251         classinfo *c;
1252
1253         TRACEJVMCALLS("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool);
1254
1255         c = LLNI_classinfo_unwrap(jcpool);
1256
1257         return c->cpcount;
1258 }
1259
1260
1261 /* JVM_ConstantPoolGetClassAt */
1262
1263 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1264 {
1265         constant_classref *ref;
1266         classinfo         *c;
1267         classinfo         *result;
1268
1269         TRACEJVMCALLS("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index);
1270
1271         c = LLNI_classinfo_unwrap(jcpool);
1272
1273         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1274
1275         if (ref == NULL)
1276                 return NULL;
1277
1278         result = resolve_classref_eager(ref);
1279
1280         return (jclass) LLNI_classinfo_wrap(result);
1281 }
1282
1283
1284 /* JVM_ConstantPoolGetClassAtIfLoaded */
1285
1286 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1287 {
1288         constant_classref *ref;
1289         classinfo         *c;
1290         classinfo         *result;
1291
1292         TRACEJVMCALLS("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index);
1293
1294         c = LLNI_classinfo_unwrap(jcpool);
1295
1296         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1297
1298         if (ref == NULL)
1299                 return NULL;
1300         
1301         if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result))
1302                 return NULL;
1303
1304         if ((result == NULL) || !(result->state & CLASS_LOADED)) {
1305                 return NULL;
1306         }
1307         
1308         return (jclass) LLNI_classinfo_wrap(result);
1309 }
1310
1311
1312 /* JVM_ConstantPoolGetMethodAt */
1313
1314 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1315 {
1316         constant_FMIref *ref;
1317         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1318         
1319         TRACEJVMCALLS("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index);
1320
1321         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1322         
1323         if (ref == NULL) {
1324                 return NULL;
1325         }
1326
1327         /* XXX: is that right? or do I have to use resolve_method_*? */
1328         return (jobject)reflect_method_new(ref->p.method);
1329 }
1330
1331
1332 /* JVM_ConstantPoolGetMethodAtIfLoaded */
1333
1334 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1335 {
1336         constant_FMIref *ref;
1337         classinfo *c = NULL;
1338         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1339
1340         TRACEJVMCALLS("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
1341
1342         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1343
1344         if (ref == NULL) {
1345                 return NULL;
1346         }
1347
1348         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1349                 return NULL;
1350         }
1351
1352         if (c == NULL || !(c->state & CLASS_LOADED)) {
1353                 return NULL;
1354         }
1355
1356         return (jobject)reflect_method_new(ref->p.method);
1357 }
1358
1359
1360 /* JVM_ConstantPoolGetFieldAt */
1361
1362 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1363 {
1364         constant_FMIref *ref;
1365         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1366         
1367         TRACEJVMCALLS("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index);
1368
1369         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1370
1371         if (ref == NULL) {
1372                 return NULL;
1373         }
1374
1375         return (jobject)reflect_field_new(ref->p.field);
1376 }
1377
1378
1379 /* JVM_ConstantPoolGetFieldAtIfLoaded */
1380
1381 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1382 {
1383         constant_FMIref *ref;
1384         classinfo *c;
1385         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1386
1387         TRACEJVMCALLS("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
1388
1389         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1390
1391         if (ref == NULL) {
1392                 return NULL;
1393         }
1394
1395         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1396                 return NULL;
1397         }
1398
1399         if (c == NULL || !(c->state & CLASS_LOADED)) {
1400                 return NULL;
1401         }
1402
1403         return (jobject)reflect_field_new(ref->p.field);
1404 }
1405
1406
1407 /* JVM_ConstantPoolGetMemberRefInfoAt */
1408
1409 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1410 {
1411         log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
1412         return NULL;
1413 }
1414
1415
1416 /* JVM_ConstantPoolGetIntAt */
1417
1418 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1419 {
1420         constant_integer *ref;
1421         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1422
1423         TRACEJVMCALLS("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index);
1424
1425         ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
1426
1427         if (ref == NULL) {
1428                 return 0;
1429         }
1430
1431         return ref->value;
1432 }
1433
1434
1435 /* JVM_ConstantPoolGetLongAt */
1436
1437 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1438 {
1439         constant_long *ref;
1440         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1441
1442         TRACEJVMCALLS("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index);
1443
1444         ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
1445
1446         if (ref == NULL) {
1447                 return 0;
1448         }
1449
1450         return ref->value;
1451 }
1452
1453
1454 /* JVM_ConstantPoolGetFloatAt */
1455
1456 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1457 {
1458         constant_float *ref;
1459         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1460
1461         TRACEJVMCALLS("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index);
1462
1463         ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
1464
1465         if (ref == NULL) {
1466                 return 0;
1467         }
1468
1469         return ref->value;
1470 }
1471
1472
1473 /* JVM_ConstantPoolGetDoubleAt */
1474
1475 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1476 {
1477         constant_double *ref;
1478         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1479
1480         TRACEJVMCALLS("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index);
1481
1482         ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
1483
1484         if (ref == NULL) {
1485                 return 0;
1486         }
1487
1488         return ref->value;
1489 }
1490
1491
1492 /* JVM_ConstantPoolGetStringAt */
1493
1494 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1495 {
1496         utf *ref;
1497         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1498
1499         TRACEJVMCALLS("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index);
1500         
1501         ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
1502
1503         if (ref == NULL) {
1504                 return NULL;
1505         }
1506
1507         /* XXX: I hope literalstring_new is the right Function. */
1508         return (jstring)literalstring_new(ref);
1509 }
1510
1511
1512 /* JVM_ConstantPoolGetUTF8At */
1513
1514 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1515 {
1516         utf *ref;
1517         classinfo *cls = LLNI_classinfo_unwrap(jcpool);
1518
1519         TRACEJVMCALLS("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index);
1520
1521         ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
1522
1523         if (ref == NULL) {
1524                 return NULL;
1525         }
1526
1527         /* XXX: I hope literalstring_new is the right Function. */
1528         return (jstring)literalstring_new(ref);
1529 }
1530
1531
1532 /* JVM_DesiredAssertionStatus */
1533
1534 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
1535 {
1536         TRACEJVMCALLS("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls);
1537
1538         /* TODO: Implement this one, but false should be OK. */
1539
1540         return false;
1541 }
1542
1543
1544 /* JVM_AssertionStatusDirectives */
1545
1546 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
1547 {
1548         classinfo                           *c;
1549         java_lang_AssertionStatusDirectives *o;
1550         java_handle_objectarray_t           *classes;
1551         java_handle_objectarray_t           *packages;
1552
1553 #if PRINTJVM || 1
1554         log_println("JVM_AssertionStatusDirectives");
1555 #endif
1556         /* XXX this is not completely implemented */
1557
1558         c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
1559
1560         if (c == NULL)
1561                 return NULL;
1562
1563         o = (java_lang_AssertionStatusDirectives *) builtin_new(c);
1564
1565         if (o == NULL)
1566                 return NULL;
1567
1568         classes = builtin_anewarray(0, class_java_lang_Object);
1569
1570         if (classes == NULL)
1571                 return NULL;
1572
1573         packages = builtin_anewarray(0, class_java_lang_Object);
1574
1575         if (packages == NULL)
1576                 return NULL;
1577
1578         /* set instance fields */
1579
1580         o->classes  = classes;
1581         o->packages = packages;
1582
1583         return (jobject) o;
1584 }
1585
1586
1587 /* JVM_GetClassNameUTF */
1588
1589 const char* JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
1590 {
1591         log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
1592 }
1593
1594
1595 /* JVM_GetClassCPTypes */
1596
1597 void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
1598 {
1599         log_println("JVM_GetClassCPTypes: IMPLEMENT ME!");
1600 }
1601
1602
1603 /* JVM_GetClassCPEntriesCount */
1604
1605 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
1606 {
1607         log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
1608 }
1609
1610
1611 /* JVM_GetClassFieldsCount */
1612
1613 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
1614 {
1615         log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
1616 }
1617
1618
1619 /* JVM_GetClassMethodsCount */
1620
1621 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
1622 {
1623         log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
1624 }
1625
1626
1627 /* JVM_GetMethodIxExceptionIndexes */
1628
1629 void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)
1630 {
1631         log_println("JVM_GetMethodIxExceptionIndexes: IMPLEMENT ME!");
1632 }
1633
1634
1635 /* JVM_GetMethodIxExceptionsCount */
1636
1637 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
1638 {
1639         log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
1640 }
1641
1642
1643 /* JVM_GetMethodIxByteCode */
1644
1645 void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)
1646 {
1647         log_println("JVM_GetMethodIxByteCode: IMPLEMENT ME!");
1648 }
1649
1650
1651 /* JVM_GetMethodIxByteCodeLength */
1652
1653 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
1654 {
1655         log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
1656 }
1657
1658
1659 /* JVM_GetMethodIxExceptionTableEntry */
1660
1661 void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)
1662 {
1663         log_println("JVM_GetMethodIxExceptionTableEntry: IMPLEMENT ME!");
1664 }
1665
1666
1667 /* JVM_GetMethodIxExceptionTableLength */
1668
1669 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
1670 {
1671         log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
1672 }
1673
1674
1675 /* JVM_GetMethodIxModifiers */
1676
1677 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
1678 {
1679         log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
1680 }
1681
1682
1683 /* JVM_GetFieldIxModifiers */
1684
1685 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
1686 {
1687         log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
1688 }
1689
1690
1691 /* JVM_GetMethodIxLocalsCount */
1692
1693 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
1694 {
1695         log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
1696 }
1697
1698
1699 /* JVM_GetMethodIxArgsSize */
1700
1701 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
1702 {
1703         log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
1704 }
1705
1706
1707 /* JVM_GetMethodIxMaxStack */
1708
1709 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
1710 {
1711         log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
1712 }
1713
1714
1715 /* JVM_IsConstructorIx */
1716
1717 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
1718 {
1719         log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
1720 }
1721
1722
1723 /* JVM_GetMethodIxNameUTF */
1724
1725 const char* JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
1726 {
1727         log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
1728 }
1729
1730
1731 /* JVM_GetMethodIxSignatureUTF */
1732
1733 const char* JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
1734 {
1735         log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
1736 }
1737
1738
1739 /* JVM_GetCPFieldNameUTF */
1740
1741 const char* JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1742 {
1743         log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
1744 }
1745
1746
1747 /* JVM_GetCPMethodNameUTF */
1748
1749 const char* JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1750 {
1751         log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
1752 }
1753
1754
1755 /* JVM_GetCPMethodSignatureUTF */
1756
1757 const char* JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1758 {
1759         log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
1760 }
1761
1762
1763 /* JVM_GetCPFieldSignatureUTF */
1764
1765 const char* JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1766 {
1767         log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
1768 }
1769
1770
1771 /* JVM_GetCPClassNameUTF */
1772
1773 const char* JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1774 {
1775         log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
1776 }
1777
1778
1779 /* JVM_GetCPFieldClassNameUTF */
1780
1781 const char* JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1782 {
1783         log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
1784 }
1785
1786
1787 /* JVM_GetCPMethodClassNameUTF */
1788
1789 const char* JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1790 {
1791         log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
1792 }
1793
1794
1795 /* JVM_GetCPFieldModifiers */
1796
1797 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1798 {
1799         log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
1800 }
1801
1802
1803 /* JVM_GetCPMethodModifiers */
1804
1805 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1806 {
1807         log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
1808 }
1809
1810
1811 /* JVM_ReleaseUTF */
1812
1813 void JVM_ReleaseUTF(const char *utf)
1814 {
1815         log_println("JVM_ReleaseUTF: IMPLEMENT ME!");
1816 }
1817
1818
1819 /* JVM_IsSameClassPackage */
1820
1821 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
1822 {
1823         log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
1824 }
1825
1826
1827 /* JVM_Open */
1828
1829 jint JVM_Open(const char *fname, jint flags, jint mode)
1830 {
1831         int result;
1832
1833 #if PRINTJVM
1834         log_println("JVM_Open: fname=%s, flags=%d, mode=%d", fname, flags, mode);
1835 #endif
1836
1837         result = open(fname, flags, mode);
1838
1839         if (result >= 0) {
1840                 return result;
1841         }
1842         else {
1843                 switch(errno) {
1844                 case EEXIST:
1845                         /* XXX don't know what to do here */
1846 /*                      return JVM_EEXIST; */
1847                         return -1;
1848                 default:
1849                         return -1;
1850                 }
1851         }
1852 }
1853
1854
1855 /* JVM_Close */
1856
1857 jint JVM_Close(jint fd)
1858 {
1859 #if PRINTJVM
1860         log_println("JVM_Close: fd=%d", fd);
1861 #endif
1862         return close(fd);
1863 }
1864
1865
1866 /* JVM_Read */
1867
1868 jint JVM_Read(jint fd, char *buf, jint nbytes)
1869 {
1870 #if PRINTJVM
1871         log_println("JVM_Read: fd=%d, buf=%p, nbytes=%d", fd, buf, nbytes);
1872 #endif
1873         return read(fd, buf, nbytes);
1874 }
1875
1876
1877 /* JVM_Write */
1878
1879 jint JVM_Write(jint fd, char *buf, jint nbytes)
1880 {
1881 #if PRINTJVM
1882         log_println("JVM_Write: fd=%d, buf=%s, nbytes=%d", fd, buf, nbytes);
1883 #endif
1884         return write(fd, buf, nbytes);
1885 }
1886
1887
1888 /* JVM_Available */
1889
1890 jint JVM_Available(jint fd, jlong *pbytes)
1891 {
1892 #if defined(FIONREAD)
1893         int bytes;
1894
1895         TRACEJVMCALLS("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes);
1896
1897         *pbytes = 0;
1898
1899         if (ioctl(fd, FIONREAD, &bytes) < 0)
1900                 return 0;
1901
1902         *pbytes = bytes;
1903
1904         return 1;
1905 #else
1906 # error FIONREAD not defined
1907 #endif
1908 }
1909
1910
1911 /* JVM_Lseek */
1912
1913 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
1914 {
1915 #if PRINTJVM
1916         log_println("JVM_Lseek: fd=%d, offset=%ld, whence=%d", fd, offset, whence);
1917 #endif
1918         return (jlong) lseek(fd, (off_t) offset, whence);
1919 }
1920
1921
1922 /* JVM_SetLength */
1923
1924 jint JVM_SetLength(jint fd, jlong length)
1925 {
1926         log_println("JVM_SetLength: IMPLEMENT ME!");
1927 }
1928
1929
1930 /* JVM_Sync */
1931
1932 jint JVM_Sync(jint fd)
1933 {
1934         log_println("JVM_Sync: IMPLEMENT ME!");
1935 }
1936
1937
1938 /* JVM_StartThread */
1939
1940 void JVM_StartThread(JNIEnv* env, jobject jthread)
1941 {
1942 #if PRINTJVM
1943         log_println("JVM_StartThread: jthread=%p", jthread);
1944 #endif
1945         _Jv_java_lang_Thread_start((java_lang_Thread *) jthread, 0);
1946 }
1947
1948
1949 /* JVM_StopThread */
1950
1951 void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
1952 {
1953         log_println("JVM_StopThread: IMPLEMENT ME!");
1954 }
1955
1956
1957 /* JVM_IsThreadAlive */
1958
1959 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
1960 {
1961 #if PRINTJVM
1962         log_println("JVM_IsThreadAlive: jthread=%p", jthread);
1963 #endif
1964         return _Jv_java_lang_Thread_isAlive((java_lang_Thread *) jthread);
1965 }
1966
1967
1968 /* JVM_SuspendThread */
1969
1970 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
1971 {
1972         log_println("JVM_SuspendThread: IMPLEMENT ME!");
1973 }
1974
1975
1976 /* JVM_ResumeThread */
1977
1978 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
1979 {
1980         log_println("JVM_ResumeThread: IMPLEMENT ME!");
1981 }
1982
1983
1984 /* JVM_SetThreadPriority */
1985
1986 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
1987 {
1988 #if PRINTJVM
1989         log_println("JVM_SetThreadPriority: jthread=%p, prio=%d", jthread, prio);
1990 #endif
1991         _Jv_java_lang_Thread_setPriority((java_lang_Thread *) jthread, prio);
1992 }
1993
1994
1995 /* JVM_Yield */
1996
1997 void JVM_Yield(JNIEnv *env, jclass threadClass)
1998 {
1999         TRACEJVMCALLS("JVM_Yield(env=%p, threadClass=%p)", env, threadClass);
2000
2001         threads_yield();
2002 }
2003
2004
2005 /* JVM_Sleep */
2006
2007 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
2008 {
2009 #if PRINTJVM
2010         log_println("JVM_Sleep: threadClass=%p, millis=%ld", threadClass, millis);
2011 #endif
2012         _Jv_java_lang_Thread_sleep(millis);
2013 }
2014
2015
2016 /* JVM_CurrentThread */
2017
2018 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
2019 {
2020 #if PRINTJVM
2021         log_println("JVM_CurrentThread: threadClass=%p", threadClass);
2022 #endif
2023         return (jobject) _Jv_java_lang_Thread_currentThread();
2024 }
2025
2026
2027 /* JVM_CountStackFrames */
2028
2029 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
2030 {
2031         log_println("JVM_CountStackFrames: IMPLEMENT ME!");
2032 }
2033
2034
2035 /* JVM_Interrupt */
2036
2037 void JVM_Interrupt(JNIEnv* env, jobject jthread)
2038 {
2039         log_println("JVM_Interrupt: IMPLEMENT ME!");
2040 }
2041
2042
2043 /* JVM_IsInterrupted */
2044
2045 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2046 {
2047 #if PRINTJVM
2048         log_println("JVM_IsInterrupted: jthread=%p, clear_interrupted=%d", jthread, clear_interrupted);
2049 #endif
2050         /* XXX do something with clear_interrupted */
2051         return _Jv_java_lang_Thread_isInterrupted((java_lang_Thread *) jthread);
2052 }
2053
2054
2055 /* JVM_HoldsLock */
2056
2057 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2058 {
2059         log_println("JVM_HoldsLock: IMPLEMENT ME!");
2060 }
2061
2062
2063 /* JVM_DumpAllStacks */
2064
2065 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2066 {
2067         log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2068 }
2069
2070
2071 /* JVM_CurrentLoadedClass */
2072
2073 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2074 {
2075         log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2076 }
2077
2078
2079 /* JVM_CurrentClassLoader */
2080
2081 jobject JVM_CurrentClassLoader(JNIEnv *env)
2082 {
2083     /* XXX if a method in a class in a trusted loader is in a
2084            doPrivileged, return NULL */
2085
2086         log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2087 }
2088
2089
2090 /* JVM_GetClassContext */
2091
2092 jobjectArray JVM_GetClassContext(JNIEnv *env)
2093 {
2094 #if PRINTJVM
2095         log_println("JVM_GetClassContext");
2096 #endif
2097         return (jobjectArray) stacktrace_getClassContext();
2098 }
2099
2100
2101 /* JVM_ClassDepth */
2102
2103 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2104 {
2105         log_println("JVM_ClassDepth: IMPLEMENT ME!");
2106 }
2107
2108
2109 /* JVM_ClassLoaderDepth */
2110
2111 jint JVM_ClassLoaderDepth(JNIEnv *env)
2112 {
2113         log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2114 }
2115
2116
2117 /* JVM_GetSystemPackage */
2118
2119 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2120 {
2121         log_println("JVM_GetSystemPackage(env=%p, name=%p)");
2122         javastring_print((java_handle_t *) name);
2123         printf("\n");
2124
2125         return NULL;
2126 }
2127
2128
2129 /* JVM_GetSystemPackages */
2130
2131 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2132 {
2133         log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2134 }
2135
2136
2137 /* JVM_AllocateNewObject */
2138
2139 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2140 {
2141         log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2142 }
2143
2144
2145 /* JVM_AllocateNewArray */
2146
2147 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2148 {
2149         log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2150 }
2151
2152
2153 /* JVM_LatestUserDefinedLoader */
2154
2155 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2156 {
2157         log_println("JVM_LatestUserDefinedLoader: IMPLEMENT ME!");
2158 }
2159
2160
2161 /* JVM_LoadClass0 */
2162
2163 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2164 {
2165         log_println("JVM_LoadClass0: IMPLEMENT ME!");
2166 }
2167
2168
2169 /* JVM_GetArrayLength */
2170
2171 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2172 {
2173         java_handle_t *a;
2174
2175         TRACEJVMCALLS("JVM_GetArrayLength(arr=%p)", arr);
2176
2177         a = (java_handle_t *) arr;
2178
2179         return array_length_get(a);
2180 }
2181
2182
2183 /* JVM_GetArrayElement */
2184
2185 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2186 {
2187         java_handle_t *a;
2188         java_handle_t *o;
2189
2190         TRACEJVMCALLS("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index);
2191
2192         a = (java_handle_t *) arr;
2193
2194 /*      if (!class_is_array(a->objheader.vftbl->class)) { */
2195 /*              exceptions_throw_illegalargumentexception(); */
2196 /*              return NULL; */
2197 /*      } */
2198
2199         o = array_element_get(a, index);
2200
2201         return (jobject) o;
2202 }
2203
2204
2205 /* JVM_GetPrimitiveArrayElement */
2206
2207 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2208 {
2209         log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2210 }
2211
2212
2213 /* JVM_SetArrayElement */
2214
2215 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2216 {
2217         java_handle_t *a;
2218         java_handle_t *value;
2219
2220         TRACEJVMCALLS("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val);
2221
2222         a     = (java_handle_t *) arr;
2223         value = (java_handle_t *) val;
2224
2225         array_element_set(a, index, value);
2226 }
2227
2228
2229 /* JVM_SetPrimitiveArrayElement */
2230
2231 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2232 {
2233         log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2234 }
2235
2236
2237 /* JVM_NewArray */
2238
2239 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2240 {
2241         classinfo                 *c;
2242         classinfo                 *pc;
2243         java_handle_t             *a;
2244         java_handle_objectarray_t *oa;
2245
2246         TRACEJVMCALLS("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length);
2247
2248         c = LLNI_classinfo_unwrap(eltClass);
2249
2250         /* create primitive or object array */
2251
2252         if (class_is_primitive(c)) {
2253                 pc = primitive_arrayclass_get_by_name(c->name);
2254                 a = builtin_newarray(length, pc);
2255
2256                 return (jobject) a;
2257         }
2258         else {
2259                 oa = builtin_anewarray(length, c);
2260
2261                 return (jobject) oa;
2262         }
2263 }
2264
2265
2266 /* JVM_NewMultiArray */
2267
2268 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2269 {
2270         log_println("JVM_NewMultiArray: IMPLEMENT ME!");
2271 }
2272
2273
2274 /* JVM_InitializeSocketLibrary */
2275
2276 jint JVM_InitializeSocketLibrary()
2277 {
2278         log_println("JVM_InitializeSocketLibrary: IMPLEMENT ME!");
2279 }
2280
2281
2282 /* JVM_Socket */
2283
2284 jint JVM_Socket(jint domain, jint type, jint protocol)
2285 {
2286         TRACEJVMCALLS("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol);
2287
2288         return socket(domain, type, protocol);
2289 }
2290
2291
2292 /* JVM_SocketClose */
2293
2294 jint JVM_SocketClose(jint fd)
2295 {
2296         TRACEJVMCALLS("JVM_SocketClose(fd=%d)", fd);
2297
2298         return close(fd);
2299 }
2300
2301
2302 /* JVM_SocketShutdown */
2303
2304 jint JVM_SocketShutdown(jint fd, jint howto)
2305 {
2306         TRACEJVMCALLS("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto);
2307
2308         return shutdown(fd, howto);
2309 }
2310
2311
2312 /* JVM_Recv */
2313
2314 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2315 {
2316         log_println("JVM_Recv: IMPLEMENT ME!");
2317 }
2318
2319
2320 /* JVM_Send */
2321
2322 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2323 {
2324         log_println("JVM_Send: IMPLEMENT ME!");
2325 }
2326
2327
2328 /* JVM_Timeout */
2329
2330 jint JVM_Timeout(int fd, long timeout)
2331 {
2332         log_println("JVM_Timeout: IMPLEMENT ME!");
2333 }
2334
2335
2336 /* JVM_Listen */
2337
2338 jint JVM_Listen(jint fd, jint count)
2339 {
2340         TRACEJVMCALLS("JVM_Listen(fd=%d, count=%d)", fd, count);
2341
2342         return listen(fd, count);
2343 }
2344
2345
2346 /* JVM_Connect */
2347
2348 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2349 {
2350         TRACEJVMCALLS("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len);
2351
2352         return connect(fd, him, len);
2353 }
2354
2355
2356 /* JVM_Bind */
2357
2358 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2359 {
2360         log_println("JVM_Bind: IMPLEMENT ME!");
2361 }
2362
2363
2364 /* JVM_Accept */
2365
2366 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2367 {
2368         TRACEJVMCALLS("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len);
2369
2370         return accept(fd, him, (socklen_t *) len);
2371 }
2372
2373
2374 /* JVM_RecvFrom */
2375
2376 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2377 {
2378         log_println("JVM_RecvFrom: IMPLEMENT ME!");
2379 }
2380
2381
2382 /* JVM_GetSockName */
2383
2384 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2385 {
2386         TRACEJVMCALLS("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len);
2387
2388         return getsockname(fd, him, (socklen_t *) len);
2389 }
2390
2391
2392 /* JVM_SendTo */
2393
2394 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2395 {
2396         log_println("JVM_SendTo: IMPLEMENT ME!");
2397 }
2398
2399
2400 /* JVM_SocketAvailable */
2401
2402 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2403 {
2404         log_println("JVM_SocketAvailable: IMPLEMENT ME!");
2405 }
2406
2407
2408 /* JVM_GetSockOpt */
2409
2410 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2411 {
2412         log_println("JVM_GetSockOpt: IMPLEMENT ME!");
2413 }
2414
2415
2416 /* JVM_SetSockOpt */
2417
2418 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2419 {
2420         TRACEJVMCALLS("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen);
2421
2422         return setsockopt(fd, level, optname, optval, optlen);
2423 }
2424
2425
2426 /* JVM_GetHostName */
2427
2428 int JVM_GetHostName(char* name, int namelen)
2429 {
2430         TRACEJVMCALLS("JVM_GetHostName(name=%s, namelen=%d)", name, namelen);
2431
2432         return gethostname(name, namelen);
2433 }
2434
2435
2436 /* JVM_GetHostByAddr */
2437
2438 struct hostent* JVM_GetHostByAddr(const char* name, int len, int type)
2439 {
2440         log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2441 }
2442
2443
2444 /* JVM_GetHostByName */
2445
2446 struct hostent* JVM_GetHostByName(char* name)
2447 {
2448         log_println("JVM_GetHostByName: IMPLEMENT ME!");
2449 }
2450
2451
2452 /* JVM_GetProtoByName */
2453
2454 struct protoent* JVM_GetProtoByName(char* name)
2455 {
2456         log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2457 }
2458
2459
2460 /* JVM_LoadLibrary */
2461
2462 void *JVM_LoadLibrary(const char *name)
2463 {
2464         utf *u;
2465
2466         TRACEJVMCALLS("JVM_LoadLibrary(name=%s)", name);
2467
2468         u = utf_new_char(name);
2469
2470         return native_library_open(u);
2471 }
2472
2473
2474 /* JVM_UnloadLibrary */
2475
2476 void JVM_UnloadLibrary(void* handle)
2477 {
2478         log_println("JVM_UnloadLibrary: IMPLEMENT ME!");
2479 }
2480
2481
2482 /* JVM_FindLibraryEntry */
2483
2484 void *JVM_FindLibraryEntry(void *handle, const char *name)
2485 {
2486         lt_ptr symbol;
2487
2488         TRACEJVMCALLS("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name);
2489
2490         symbol = lt_dlsym(handle, name);
2491
2492         return symbol;
2493 }
2494
2495
2496 /* JVM_IsNaN */
2497
2498 jboolean JVM_IsNaN(jdouble a)
2499 {
2500         log_println("JVM_IsNaN: IMPLEMENT ME!");
2501 }
2502
2503
2504 /* JVM_IsSupportedJNIVersion */
2505
2506 jboolean JVM_IsSupportedJNIVersion(jint version)
2507 {
2508         TRACEJVMCALLS("JVM_IsSupportedJNIVersion(version=%d)", version);
2509
2510         switch (version) {
2511         case JNI_VERSION_1_1:
2512         case JNI_VERSION_1_2:
2513         case JNI_VERSION_1_4:
2514                 return true;
2515         default:
2516                 return false;
2517         }
2518 }
2519
2520
2521 /* JVM_InternString */
2522
2523 jstring JVM_InternString(JNIEnv *env, jstring str)
2524 {
2525         TRACEJVMCALLS("JVM_InternString(env=%p, str=%p)", env, str);
2526
2527         return (jstring) javastring_intern((java_handle_t *) str);
2528 }
2529
2530
2531 /* JVM_RawMonitorCreate */
2532
2533 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
2534 {
2535         java_object_t *o;
2536
2537 #if PRINTJVM
2538         log_println("JVM_RawMonitorCreate");
2539 #endif
2540
2541         o = NEW(java_object_t);
2542
2543         lock_init_object_lock(o);
2544
2545         return o;
2546 }
2547
2548
2549 /* JVM_RawMonitorDestroy */
2550
2551 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
2552 {
2553 #if PRINTJVM
2554         log_println("JVM_RawMonitorDestroy: mon=%p", mon);
2555 #endif
2556         FREE(mon, java_object_t);
2557 }
2558
2559
2560 /* JVM_RawMonitorEnter */
2561
2562 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
2563 {
2564 #if PRINTJVM
2565         log_println("JVM_RawMonitorEnter: mon=%p", mon);
2566 #endif
2567         (void) lock_monitor_enter((java_object_t *) mon);
2568
2569         return 0;
2570 }
2571
2572
2573 /* JVM_RawMonitorExit */
2574
2575 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
2576 {
2577 #if PRINTJVM
2578         log_println("JVM_RawMonitorExit: mon=%p", mon);
2579 #endif
2580         (void) lock_monitor_exit((java_object_t *) mon);
2581 }
2582
2583
2584 /* JVM_SetPrimitiveFieldValues */
2585
2586 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
2587 {
2588         log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
2589 }
2590
2591
2592 /* JVM_GetPrimitiveFieldValues */
2593
2594 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
2595 {
2596         log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
2597 }
2598
2599
2600 /* JVM_AccessVMBooleanFlag */
2601
2602 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
2603 {
2604         log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
2605 }
2606
2607
2608 /* JVM_AccessVMIntFlag */
2609
2610 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
2611 {
2612         log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
2613 }
2614
2615
2616 /* JVM_VMBreakPoint */
2617
2618 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
2619 {
2620         log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
2621 }
2622
2623
2624 /* JVM_GetClassFields */
2625
2626 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
2627 {
2628         log_println("JVM_GetClassFields: IMPLEMENT ME!");
2629 }
2630
2631
2632 /* JVM_GetClassMethods */
2633
2634 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
2635 {
2636         log_println("JVM_GetClassMethods: IMPLEMENT ME!");
2637 }
2638
2639
2640 /* JVM_GetClassConstructors */
2641
2642 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
2643 {
2644         log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
2645 }
2646
2647
2648 /* JVM_GetClassField */
2649
2650 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
2651 {
2652         log_println("JVM_GetClassField: IMPLEMENT ME!");
2653 }
2654
2655
2656 /* JVM_GetClassMethod */
2657
2658 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
2659 {
2660         log_println("JVM_GetClassMethod: IMPLEMENT ME!");
2661 }
2662
2663
2664 /* JVM_GetClassConstructor */
2665
2666 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
2667 {
2668         log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
2669 }
2670
2671
2672 /* JVM_NewInstance */
2673
2674 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
2675 {
2676         log_println("JVM_NewInstance: IMPLEMENT ME!");
2677 }
2678
2679
2680 /* JVM_GetField */
2681
2682 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
2683 {
2684         log_println("JVM_GetField: IMPLEMENT ME!");
2685 }
2686
2687
2688 /* JVM_GetPrimitiveField */
2689
2690 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
2691 {
2692         log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
2693 }
2694
2695
2696 /* JVM_SetField */
2697
2698 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
2699 {
2700         log_println("JVM_SetField: IMPLEMENT ME!");
2701 }
2702
2703
2704 /* JVM_SetPrimitiveField */
2705
2706 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
2707 {
2708         log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
2709 }
2710
2711
2712 /* JVM_InvokeMethod */
2713
2714 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
2715 {
2716 #if PRINTJVM
2717         log_println("JVM_InvokeMethod: method=%p, obj=%p, args0=%p", method, obj, args0);
2718 #endif
2719         return (jobject) _Jv_java_lang_reflect_Method_invoke((java_lang_reflect_Method *) method, (java_lang_Object *) obj, (java_handle_objectarray_t *) args0);
2720 }
2721
2722
2723 /* JVM_NewInstanceFromConstructor */
2724
2725 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)
2726 {
2727 #if PRINTJVM
2728         log_println("JVM_NewInstanceFromConstructor: c=%p, args0=%p", c, args0);
2729 #endif
2730         return (jobject) _Jv_java_lang_reflect_Constructor_newInstance(env, (java_lang_reflect_Constructor *) c, (java_handle_objectarray_t *) args0);
2731 }
2732
2733
2734 /* JVM_SupportsCX8 */
2735
2736 jboolean JVM_SupportsCX8()
2737 {
2738 #if PRINTJVM
2739         log_println("JVM_SupportsCX8");
2740 #endif
2741         return _Jv_java_util_concurrent_atomic_AtomicLong_VMSupportsCS8(NULL, NULL);
2742 }
2743
2744
2745 /* JVM_CX8Field */
2746
2747 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
2748 {
2749         log_println("JVM_CX8Field: IMPLEMENT ME!");
2750 }
2751
2752
2753 /* JVM_GetAllThreads */
2754
2755 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
2756 {
2757         log_println("JVM_GetAllThreads: IMPLEMENT ME!");
2758 }
2759
2760
2761 /* JVM_DumpThreads */
2762
2763 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
2764 {
2765         log_println("JVM_DumpThreads: IMPLEMENT ME!");
2766 }
2767
2768
2769 /* JVM_GetManagement */
2770
2771 void* JVM_GetManagement(jint version)
2772 {
2773         log_println("JVM_GetManagement: IMPLEMENT ME!");
2774 }
2775
2776
2777 /* JVM_InitAgentProperties */
2778
2779 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
2780 {
2781         log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
2782 }
2783
2784
2785 /* JVM_GetEnclosingMethodInfo */
2786
2787 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
2788 {
2789         log_println("JVM_GetEnclosingMethodInfo: IMPLEMENT ME!");
2790 }
2791
2792
2793 /* JVM_GetThreadStateValues */
2794
2795 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
2796 {
2797         java_handle_intarray_t *ia;
2798
2799         TRACEJVMCALLS("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
2800                                   env, javaThreadState);
2801
2802         /* If new thread states are added in future JDK and VM versions,
2803            this should check if the JDK version is compatible with thread
2804            states supported by the VM.  Return NULL if not compatible.
2805         
2806            This function must map the VM java_lang_Thread::ThreadStatus
2807            to the Java thread state that the JDK supports. */
2808
2809         switch (javaThreadState) {
2810     case THREAD_STATE_NEW:
2811                 ia = builtin_newarray_int(1);
2812
2813                 if (ia == NULL)
2814                         return NULL;
2815
2816                 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
2817                 break; 
2818
2819     case THREAD_STATE_RUNNABLE:
2820                 ia = builtin_newarray_int(1);
2821
2822                 if (ia == NULL)
2823                         return NULL;
2824
2825                 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
2826                 break; 
2827
2828     case THREAD_STATE_BLOCKED:
2829                 ia = builtin_newarray_int(1);
2830
2831                 if (ia == NULL)
2832                         return NULL;
2833
2834                 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
2835                 break; 
2836
2837     case THREAD_STATE_WAITING:
2838                 ia = builtin_newarray_int(2);
2839
2840                 if (ia == NULL)
2841                         return NULL;
2842
2843                 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
2844                 /* XXX Implement parked stuff. */
2845 /*              array_intarray_element_set(ia, 1, PARKED); */
2846                 break; 
2847
2848     case THREAD_STATE_TIMED_WAITING:
2849                 ia = builtin_newarray_int(3);
2850
2851                 if (ia == NULL)
2852                         return NULL;
2853
2854                 /* XXX Not sure about that one. */
2855 /*              array_intarray_element_set(ia, 0, SLEEPING); */
2856                 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
2857                 /* XXX Implement parked stuff. */
2858 /*              array_intarray_element_set(ia, 2, PARKED); */
2859                 break; 
2860
2861     case THREAD_STATE_TERMINATED:
2862                 ia = builtin_newarray_int(1);
2863
2864                 if (ia == NULL)
2865                         return NULL;
2866
2867                 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
2868                 break; 
2869
2870     default:
2871                 /* Unknown state - probably incompatible JDK version */
2872                 return NULL;
2873         }
2874
2875         return (jintArray) ia;
2876 }
2877
2878
2879 /* JVM_GetThreadStateNames */
2880
2881 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
2882 {
2883         java_handle_intarray_t    *ia;
2884         java_handle_objectarray_t *oa;
2885         java_object_t             *s;
2886
2887         TRACEJVMCALLS("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
2888                                   env, javaThreadState, values);
2889
2890         ia = (java_handle_intarray_t *) values;
2891
2892         /* If new thread states are added in future JDK and VM versions,
2893            this should check if the JDK version is compatible with thread
2894            states supported by the VM.  Return NULL if not compatible.
2895         
2896            This function must map the VM java_lang_Thread::ThreadStatus
2897            to the Java thread state that the JDK supports. */
2898
2899         if (values == NULL) {
2900                 exceptions_throw_nullpointerexception();
2901                 return NULL;
2902         }
2903
2904         switch (javaThreadState) {
2905     case THREAD_STATE_NEW:
2906                 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
2907
2908                 oa = builtin_anewarray(1, class_java_lang_String);
2909
2910                 if (oa == NULL)
2911                         return NULL;
2912
2913                 s = javastring_new(utf_new_char("NEW"));
2914
2915                 if (s == NULL)
2916                         return NULL;
2917
2918                 array_objectarray_element_set(oa, 0, s);
2919                 break; 
2920
2921     case THREAD_STATE_RUNNABLE:
2922                 oa = builtin_anewarray(1, class_java_lang_String);
2923
2924                 if (oa == NULL)
2925                         return NULL;
2926
2927                 s = javastring_new(utf_new_char("RUNNABLE"));
2928
2929                 if (s == NULL)
2930                         return NULL;
2931
2932                 array_objectarray_element_set(oa, 0, s);
2933                 break; 
2934
2935     case THREAD_STATE_BLOCKED:
2936                 oa = builtin_anewarray(1, class_java_lang_String);
2937
2938                 if (oa == NULL)
2939                         return NULL;
2940
2941                 s = javastring_new(utf_new_char("BLOCKED"));
2942
2943                 if (s == NULL)
2944                         return NULL;
2945
2946                 array_objectarray_element_set(oa, 0, s);
2947                 break; 
2948
2949     case THREAD_STATE_WAITING:
2950                 oa = builtin_anewarray(2, class_java_lang_String);
2951
2952                 if (oa == NULL)
2953                         return NULL;
2954
2955                 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
2956 /*              s = javastring_new(utf_new_char("WAITING.PARKED")); */
2957
2958                 if (s == NULL)
2959                         return NULL;
2960
2961                 array_objectarray_element_set(oa, 0, s);
2962 /*              array_objectarray_element_set(oa, 1, s); */
2963                 break; 
2964
2965     case THREAD_STATE_TIMED_WAITING:
2966                 oa = builtin_anewarray(3, class_java_lang_String);
2967
2968                 if (oa == NULL)
2969                         return NULL;
2970
2971 /*              s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
2972                 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
2973 /*              s = javastring_new(utf_new_char("TIMED_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, 0, s);
2980 /*              array_objectarray_element_set(oa, 2, s); */
2981                 break; 
2982
2983     case THREAD_STATE_TERMINATED:
2984                 oa = builtin_anewarray(1, class_java_lang_String);
2985
2986                 if (oa == NULL)
2987                         return NULL;
2988
2989                 s = javastring_new(utf_new_char("TERMINATED"));
2990
2991                 if (s == NULL)
2992                         return NULL;
2993
2994                 array_objectarray_element_set(oa, 0, s);
2995                 break; 
2996
2997         default:
2998                 /* Unknown state - probably incompatible JDK version */
2999                 return NULL;
3000         }
3001
3002         return (jobjectArray) oa;
3003 }
3004
3005
3006 /* JVM_GetVersionInfo */
3007
3008 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3009 {
3010         log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3011 }
3012
3013
3014 /* OS: JVM_RegisterSignal */
3015
3016 void *JVM_RegisterSignal(jint sig, void *handler)
3017 {
3018         functionptr newHandler;
3019
3020         TRACEJVMCALLS("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler);
3021
3022         if (handler == (void *) 2)
3023                 newHandler = (functionptr) signal_thread_handler;
3024         else
3025                 newHandler = (functionptr) (uintptr_t) handler;
3026
3027         switch (sig) {
3028     case SIGILL:
3029     case SIGFPE:
3030     case SIGUSR1:
3031     case SIGSEGV:
3032                 /* These signals are already used by the VM. */
3033                 return (void *) -1;
3034
3035     case SIGQUIT:
3036                 /* This signal is used by the VM to dump thread stacks unless
3037                    ReduceSignalUsage is set, in which case the user is allowed
3038                    to set his own _native_ handler for this signal; thus, in
3039                    either case, we do not allow JVM_RegisterSignal to change
3040                    the handler. */
3041                 return (void *) -1;
3042
3043         case SIGHUP:
3044         case SIGINT:
3045         case SIGTERM:
3046                 break;
3047         }
3048
3049         signal_register_signal(sig, newHandler, 0);
3050
3051         /* XXX Should return old handler. */
3052
3053         return (void *) 2;
3054 }
3055
3056
3057 /* OS: JVM_RaiseSignal */
3058
3059 jboolean JVM_RaiseSignal(jint sig)
3060 {
3061         log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3062         return false;
3063 }
3064
3065
3066 /* OS: JVM_FindSignal */
3067
3068 jint JVM_FindSignal(const char *name)
3069 {
3070         TRACEJVMCALLS("JVM_FindSignal(name=%s)", name);
3071
3072 #if defined(__LINUX__)
3073         if (strcmp(name, "HUP") == 0)
3074                 return SIGHUP;
3075
3076         if (strcmp(name, "INT") == 0)
3077                 return SIGINT;
3078
3079         if (strcmp(name, "TERM") == 0)
3080                 return SIGTERM;
3081 #else
3082 # error not implemented for this OS
3083 #endif
3084
3085         return -1;
3086 }
3087
3088
3089 /*
3090  * These are local overrides for various environment variables in Emacs.
3091  * Please do not remove this and leave it at the end of the file, where
3092  * Emacs will automagically detect them.
3093  * ---------------------------------------------------------------------
3094  * Local variables:
3095  * mode: c
3096  * indent-tabs-mode: t
3097  * c-basic-offset: 4
3098  * tab-width: 4
3099  * End:
3100  */