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