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