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