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