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