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