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