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