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