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