* src/threads/threadlist.hpp (ThreadList::get_active_threads): Added.
[cacao.git] / src / native / vm / openjdk / jvm.cpp
1 /* src/native/vm/openjdk/jvm.cpp - HotSpot VM interface functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <errno.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <unistd.h>
34
35 #if defined(HAVE_SYS_IOCTL_H)
36 #define BSD_COMP /* Get FIONREAD on Solaris2 */
37 #include <sys/ioctl.h>
38 #endif
39
40 #include <sys/socket.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
43
44 // Include our JNI header before the JVM headers, because the JVM
45 // headers include jni.h and we want to override the typedefs in
46 // jni.h.
47 #include "native/jni.hpp"
48
49 // We include jvm_md.h before jvm.h as the latter includes the former.
50 #include INCLUDE_JVM_MD_H
51 #include INCLUDE_JVM_H
52
53 #include "fdlibm/fdlibm.h"
54
55 #include "mm/memory.hpp"
56
57 #include "native/llni.h"
58 #include "native/native.hpp"
59
60 #include "native/vm/reflection.hpp"
61
62 #include "native/vm/openjdk/hpi.hpp"
63 #include "native/vm/openjdk/management.hpp"
64
65 #include "threads/lock.hpp"
66 #include "threads/thread.hpp"
67 #include "threads/threadlist.hpp"
68
69 #include "toolbox/logging.hpp"
70 #include "toolbox/list.hpp"
71
72 #include "vm/array.hpp"
73
74 #if defined(ENABLE_ASSERTION)
75 #include "vm/assertion.hpp"
76 #endif
77
78 #include "vm/jit/builtin.hpp"
79 #include "vm/classcache.hpp"
80 #include "vm/exceptions.hpp"
81 #include "vm/global.h"
82 #include "vm/globals.hpp"
83 #include "vm/initialize.hpp"
84 #include "vm/javaobjects.hpp"
85 #include "vm/options.h"
86 #include "vm/os.hpp"
87 #include "vm/package.hpp"
88 #include "vm/primitive.hpp"
89 #include "vm/properties.hpp"
90 #include "vm/resolve.hpp"
91 #include "vm/signallocal.hpp"
92 #include "vm/string.hpp"
93 #include "vm/vm.hpp"
94
95 #include "vm/jit/stacktrace.hpp"
96
97
98 /* debugging macros ***********************************************************/
99
100 #if !defined(NDEBUG)
101
102 # define TRACEJVMCALLS(x)                                                                               \
103     do {                                                                                                                \
104         if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {    \
105             log_println x;                                                                              \
106         }                                                                                                               \
107     } while (0)
108
109 # define TRACEJVMCALLSENTER(x)                                                                  \
110     do {                                                                                                                \
111         if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {    \
112                         log_start();                                                                            \
113             log_print x;                                                                                \
114         }                                                                                                               \
115     } while (0)
116
117 # define TRACEJVMCALLSEXIT(x)                                                                   \
118     do {                                                                                                                \
119         if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {    \
120                         log_print x;                                                                            \
121                         log_finish();                                                                           \
122         }                                                                                                               \
123     } while (0)
124
125 # define TRACEJVMCALLSVERBOSE(x)                                \
126     do {                                                                                \
127         if (opt_TraceJVMCallsVerbose) {                 \
128             log_println x;                                              \
129         }                                                                               \
130     } while (0)
131
132 # define PRINTJVMWARNINGS(x)
133 /*     do { \ */
134 /*         if (opt_PrintJVMWarnings) { \ */
135 /*             log_println x; \ */
136 /*         } \ */
137 /*     } while (0) */
138
139 #else
140
141 # define TRACEJVMCALLS(x)
142 # define TRACEJVMCALLSENTER(x)
143 # define TRACEJVMCALLSEXIT(x)
144 # define TRACEJVMCALLSVERBOSE(x)
145 # define PRINTJVMWARNINGS(x)
146
147 #endif
148
149
150 // Interface functions are exported as C functions.
151 extern "C" {
152
153 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
154 {
155         if ((intptr_t) count <= 0)
156                 return -1;
157
158         return vsnprintf(str, count, fmt, args);
159 }
160
161
162 int jio_snprintf(char *str, size_t count, const char *fmt, ...)
163 {
164         va_list ap;
165         int     len;
166
167         va_start(ap, fmt);
168         len = jio_vsnprintf(str, count, fmt, ap);
169         va_end(ap);
170
171         return len;
172 }
173
174
175 int jio_fprintf(FILE* f, const char *fmt, ...)
176 {
177         log_println("jio_fprintf: IMPLEMENT ME!");
178
179         return 0;
180 }
181
182
183 int jio_vfprintf(FILE* f, const char *fmt, va_list args)
184 {
185         log_println("jio_vfprintf: IMPLEMENT ME!");
186
187         return 0;
188 }
189
190
191 int jio_printf(const char *fmt, ...)
192 {
193         log_println("jio_printf: IMPLEMENT ME!");
194
195         return 0;
196 }
197
198
199 /* JVM_GetInterfaceVersion */
200
201 jint JVM_GetInterfaceVersion()
202 {
203         /* This is defined in hotspot/src/share/vm/prims/jvm.h */
204
205 #define JVM_INTERFACE_VERSION 4
206
207         return JVM_INTERFACE_VERSION;
208 }
209
210
211 /* JVM_CurrentTimeMillis */
212
213 jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
214 {
215         TRACEJVMCALLS(("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored));
216
217         return (jlong) builtin_currenttimemillis();
218 }
219
220
221 /* JVM_NanoTime */
222
223 jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
224 {
225         TRACEJVMCALLS(("JVM_NanoTime(env=%p, ignored=%p)", env, ignored));
226
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         TRACEJVMCALLSVERBOSE(("JVM_ArrayCopy(env=%p, ignored=%p, src=%p, src_pos=%d, dst=%p, dst_pos=%d, length=%d)", env, ignored, src, src_pos, dst, dst_pos, length));
242
243         builtin_arraycopy(s, src_pos, d, dst_pos, length);
244 }
245
246
247 /* JVM_InitProperties */
248
249 jobject JVM_InitProperties(JNIEnv *env, jobject properties)
250 {
251         java_handle_t *h;
252         char           buf[256];
253
254         TRACEJVMCALLS(("JVM_InitProperties(env=%p, properties=%p)", env, properties));
255
256         h = (java_handle_t *) properties;
257
258         /* Convert the -XX:MaxDirectMemorySize= command line flag to the
259            sun.nio.MaxDirectMemorySize property.  Do this after setting
260            user properties to prevent people from setting the value with a
261            -D option, as requested. */
262
263         jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
264         VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
265
266         // Fill the java.util.Properties object.
267         VM::get_current()->get_properties().fill(h);
268
269         return properties;
270 }
271
272
273 /* JVM_Exit */
274
275 void JVM_Exit(jint code)
276 {
277         log_println("JVM_Exit: IMPLEMENT ME!");
278 }
279
280
281 /* JVM_Halt */
282
283 void JVM_Halt(jint code)
284 {
285         TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
286
287 /*      vm_exit(code); */
288         vm_shutdown(code);
289 }
290
291
292 /* JVM_OnExit(void (*func)) */
293
294 void JVM_OnExit(void (*func)(void))
295 {
296         log_println("JVM_OnExit(void (*func): IMPLEMENT ME!");
297 }
298
299
300 /* JVM_GC */
301
302 void JVM_GC(void)
303 {
304         TRACEJVMCALLS(("JVM_GC()"));
305
306         gc_call();
307 }
308
309
310 /* JVM_MaxObjectInspectionAge */
311
312 jlong JVM_MaxObjectInspectionAge(void)
313 {
314         log_println("JVM_MaxObjectInspectionAge: IMPLEMENT ME!");
315
316         return 0;
317 }
318
319
320 /* JVM_TraceInstructions */
321
322 void JVM_TraceInstructions(jboolean on)
323 {
324         log_println("JVM_TraceInstructions: IMPLEMENT ME!");
325 }
326
327
328 /* JVM_TraceMethodCalls */
329
330 void JVM_TraceMethodCalls(jboolean on)
331 {
332         log_println("JVM_TraceMethodCalls: IMPLEMENT ME!");
333 }
334
335
336 /* JVM_TotalMemory */
337
338 jlong JVM_TotalMemory(void)
339 {
340         TRACEJVMCALLS(("JVM_TotalMemory()"));
341
342         return gc_get_heap_size();
343 }
344
345
346 /* JVM_FreeMemory */
347
348 jlong JVM_FreeMemory(void)
349 {
350         TRACEJVMCALLS(("JVM_FreeMemory()"));
351
352         return gc_get_free_bytes();
353 }
354
355
356 /* JVM_MaxMemory */
357
358 jlong JVM_MaxMemory(void)
359 {
360         TRACEJVMCALLS(("JVM_MaxMemory()"));
361
362         return gc_get_max_heap_size();
363 }
364
365
366 /* JVM_ActiveProcessorCount */
367
368 jint JVM_ActiveProcessorCount(void)
369 {
370         TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
371
372         return os::processors_online();
373 }
374
375
376 /* JVM_FillInStackTrace */
377
378 void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
379 {
380         TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
381
382         java_handle_bytearray_t* ba = stacktrace_get_current();
383
384         if (ba == NULL)
385                 return;
386
387         java_lang_Throwable jlt(receiver, ba);
388 }
389
390
391 /* JVM_PrintStackTrace */
392
393 void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
394 {
395         log_println("JVM_PrintStackTrace: IMPLEMENT ME!");
396 }
397
398
399 /* JVM_GetStackTraceDepth */
400
401 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
402 {
403         TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
404
405         java_lang_Throwable jlt(throwable);
406
407         if (jlt.is_null()) {
408                 exceptions_throw_nullpointerexception();
409                 return 0;
410         }
411
412         java_handle_bytearray_t* ba = jlt.get_backtrace();
413
414         if (ba == NULL)
415                 return 0;
416
417         // We need a critical section here as the stacktrace structure is
418         // mapped onto a Java byte-array.
419
420         LLNI_CRITICAL_START;
421
422         stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
423
424         int32_t depth = st->length;
425
426         LLNI_CRITICAL_END;
427
428         return depth;
429 }
430
431
432 /* JVM_GetStackTraceElement */
433
434 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
435 {
436         TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
437
438         java_lang_Throwable jlt(throwable);
439         java_handle_bytearray_t* ba = jlt.get_backtrace();
440
441         // XXX We need a critical section here as the stacktrace structure is
442         // mapped onto a Java byte-array.
443         stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
444
445         return stacktrace_get_StackTraceElement(st, index);
446 }
447
448
449 /* JVM_IHashCode */
450
451 jint JVM_IHashCode(JNIEnv* env, jobject handle)
452 {
453         TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
454
455         java_lang_Object o(handle);
456
457         return o.get_hashcode();
458 }
459
460
461 /* JVM_MonitorWait */
462
463 void JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)
464 {
465 #if defined(ENABLE_THREADS)
466         java_handle_t *o;
467 #endif
468
469         TRACEJVMCALLS(("JVM_MonitorWait(env=%p, handle=%p, ms=%ld)", env, handle, ms));
470     if (ms < 0) {
471 /*              exceptions_throw_illegalargumentexception("argument out of range"); */
472                 exceptions_throw_illegalargumentexception();
473                 return;
474         }
475
476 #if defined(ENABLE_THREADS)
477         o = (java_handle_t *) handle;
478
479         lock_wait_for_object(o, ms, 0);
480 #endif
481 }
482
483
484 /* JVM_MonitorNotify */
485
486 void JVM_MonitorNotify(JNIEnv* env, jobject handle)
487 {
488 #if defined(ENABLE_THREADS)
489         java_handle_t *o;
490 #endif
491
492         TRACEJVMCALLS(("JVM_MonitorNotify(env=%p, handle=%p)", env, handle));
493
494 #if defined(ENABLE_THREADS)
495         o = (java_handle_t *) handle;
496
497         lock_notify_object(o);
498 #endif
499 }
500
501
502 /* JVM_MonitorNotifyAll */
503
504 void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
505 {
506 #if defined(ENABLE_THREADS)
507         java_handle_t *o;
508 #endif
509
510         TRACEJVMCALLS(("JVM_MonitorNotifyAll(env=%p, handle=%p)", env, handle));
511
512 #if defined(ENABLE_THREADS)
513         o = (java_handle_t *) handle;
514
515         lock_notify_all_object(o);
516 #endif
517 }
518
519
520 /* JVM_Clone */
521
522 jobject JVM_Clone(JNIEnv* env, jobject handle)
523 {
524         TRACEJVMCALLS(("JVM_Clone(env=%p, handle=%p)", env, handle));
525
526         return (jobject) builtin_clone(env, (java_handle_t *) handle);
527 }
528
529
530 /* JVM_InitializeCompiler  */
531
532 void JVM_InitializeCompiler (JNIEnv *env, jclass compCls)
533 {
534         log_println("JVM_InitializeCompiler : IMPLEMENT ME!");
535 }
536
537
538 /* JVM_IsSilentCompiler */
539
540 jboolean JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)
541 {
542         log_println("JVM_IsSilentCompiler: IMPLEMENT ME!");
543
544         return 0;
545 }
546
547
548 /* JVM_CompileClass */
549
550 jboolean JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)
551 {
552         log_println("JVM_CompileClass: IMPLEMENT ME!");
553
554         return 0;
555 }
556
557
558 /* JVM_CompileClasses */
559
560 jboolean JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)
561 {
562         log_println("JVM_CompileClasses: IMPLEMENT ME!");
563
564         return 0;
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         return 0;
575 }
576
577
578 /* JVM_EnableCompiler */
579
580 void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
581 {
582         TRACEJVMCALLS(("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls));
583         PRINTJVMWARNINGS(("JVM_EnableCompiler not supported"));
584 }
585
586
587 /* JVM_DisableCompiler */
588
589 void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
590 {
591         TRACEJVMCALLS(("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls));
592         PRINTJVMWARNINGS(("JVM_DisableCompiler not supported"));
593 }
594
595
596 /* JVM_GetLastErrorString */
597
598 jint JVM_GetLastErrorString(char* buf, int len)
599 {
600         TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
601
602         HPI& hpi = VM::get_current()->get_hpi();
603         return hpi.get_system().GetLastErrorString(buf, len);
604 }
605
606
607 /* JVM_NativePath */
608
609 char *JVM_NativePath(char* path)
610 {
611         TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
612
613         HPI& hpi = VM::get_current()->get_hpi();
614         return hpi.get_file().NativePath(path);
615 }
616
617
618 /* JVM_GetCallerClass */
619
620 jclass JVM_GetCallerClass(JNIEnv* env, int depth)
621 {
622         classinfo *c;
623
624         TRACEJVMCALLS(("JVM_GetCallerClass(env=%p, depth=%d)", env, depth));
625
626         c = stacktrace_get_caller_class(depth);
627
628         return (jclass) c;
629 }
630
631
632 /* JVM_FindPrimitiveClass */
633
634 jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
635 {
636         classinfo *c;
637         utf       *u;
638
639         TRACEJVMCALLS(("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s));
640
641         u = utf_new_char(s);
642         c = Primitive::get_class_by_name(u);
643
644         return (jclass) LLNI_classinfo_wrap(c);
645 }
646
647
648 /* JVM_ResolveClass */
649
650 void JVM_ResolveClass(JNIEnv* env, jclass cls)
651 {
652         TRACEJVMCALLS(("JVM_ResolveClass(env=%p, cls=%p)", env, cls));
653         PRINTJVMWARNINGS(("JVM_ResolveClass not implemented"));
654 }
655
656
657 /* JVM_FindClassFromClassLoader */
658
659 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
660 {
661         classinfo     *c;
662         utf           *u;
663         classloader_t *cl;
664
665         TRACEJVMCALLS(("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError));
666
667         /* As of now, OpenJDK does not call this function with throwError
668            is true. */
669
670         assert(throwError == false);
671
672         u  = utf_new_char(name);
673         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
674
675         c = load_class_from_classloader(u, cl);
676
677         if (c == NULL)
678                 return NULL;
679
680         if (init)
681                 if (!(c->state & CLASS_INITIALIZED))
682                         if (!initialize_class(c))
683                                 return NULL;
684
685         return (jclass) LLNI_classinfo_wrap(c);
686 }
687
688
689 /* JVM_FindClassFromClass */
690
691 jclass JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, jclass from)
692 {
693         log_println("JVM_FindClassFromClass: IMPLEMENT ME!");
694
695         return NULL;
696 }
697
698
699 /* JVM_DefineClass */
700
701 jclass JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)
702 {
703         log_println("JVM_DefineClass: IMPLEMENT ME!");
704
705         return NULL;
706 }
707
708
709 /* JVM_DefineClassWithSource */
710
711 jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)
712 {
713         classinfo     *c;
714         utf           *u;
715         classloader_t *cl;
716
717         TRACEJVMCALLS(("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source));
718
719         if (name != NULL)
720                 u = utf_new_char(name);
721         else
722                 u = NULL;
723
724         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
725
726         /* XXX do something with source */
727
728         c = class_define(u, cl, len, (uint8_t *) buf, (java_handle_t *) pd);
729
730         return (jclass) LLNI_classinfo_wrap(c);
731 }
732
733
734 /* JVM_FindLoadedClass */
735
736 jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
737 {
738         classloader_t *cl;
739         utf           *u;
740         classinfo     *c;
741
742         TRACEJVMCALLS(("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name));
743
744         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
745
746         u = javastring_toutf((java_handle_t *) name, true);
747         c = classcache_lookup(cl, u);
748
749         return (jclass) LLNI_classinfo_wrap(c);
750 }
751
752
753 /* JVM_GetClassName */
754
755 jstring JVM_GetClassName(JNIEnv *env, jclass cls)
756 {
757         classinfo* c;
758
759         TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
760
761         c = LLNI_classinfo_unwrap(cls);
762
763         return (jstring) class_get_classname(c);
764 }
765
766
767 /* JVM_GetClassInterfaces */
768
769 jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
770 {
771         classinfo                 *c;
772         java_handle_objectarray_t *oa;
773
774         TRACEJVMCALLS(("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls));
775
776         c = LLNI_classinfo_unwrap(cls);
777
778         oa = class_get_interfaces(c);
779
780         return (jobjectArray) oa;
781 }
782
783
784 /* JVM_GetClassLoader */
785
786 jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
787 {
788         classinfo     *c;
789         classloader_t *cl;
790
791         TRACEJVMCALLSENTER(("JVM_GetClassLoader(env=%p, cls=%p)", env, cls));
792
793         c  = LLNI_classinfo_unwrap(cls);
794         cl = class_get_classloader(c);
795
796         TRACEJVMCALLSEXIT(("->%p", cl));
797
798         return (jobject) cl;
799 }
800
801
802 /* JVM_IsInterface */
803
804 jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
805 {
806         classinfo *c;
807
808         TRACEJVMCALLS(("JVM_IsInterface(env=%p, cls=%p)", env, cls));
809
810         c = LLNI_classinfo_unwrap(cls);
811
812         return class_is_interface(c);
813 }
814
815
816 /* JVM_GetClassSigners */
817
818 jobjectArray JVM_GetClassSigners(JNIEnv *env, jclass cls)
819 {
820         log_println("JVM_GetClassSigners: IMPLEMENT ME!");
821
822         return NULL;
823 }
824
825
826 /* JVM_SetClassSigners */
827
828 void JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)
829 {
830         classinfo                 *c;
831         java_handle_objectarray_t *hoa;
832
833         TRACEJVMCALLS(("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers));
834
835         c = LLNI_classinfo_unwrap(cls);
836
837         hoa = (java_handle_objectarray_t *) signers;
838
839     /* This call is ignored for primitive types and arrays.  Signers
840            are only set once, ClassLoader.java, and thus shouldn't be
841            called with an array.  Only the bootstrap loader creates
842            arrays. */
843
844         if (class_is_primitive(c) || class_is_array(c))
845                 return;
846
847         LLNI_classinfo_field_set(c, signers, hoa);
848 }
849
850
851 /* JVM_GetProtectionDomain */
852
853 jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
854 {
855         classinfo *c;
856
857         TRACEJVMCALLS(("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls));
858
859         c = LLNI_classinfo_unwrap(cls);
860
861         if (c == NULL) {
862                 exceptions_throw_nullpointerexception();
863                 return NULL;
864         }
865
866     /* Primitive types do not have a protection domain. */
867
868         if (class_is_primitive(c))
869                 return NULL;
870
871         return (jobject) c->protectiondomain;
872 }
873
874
875 /* JVM_SetProtectionDomain */
876
877 void JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain)
878 {
879         log_println("JVM_SetProtectionDomain: IMPLEMENT ME!");
880 }
881
882
883 /* JVM_DoPrivileged */
884
885 jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
886 {
887         java_handle_t *h;
888         classinfo     *c;
889         methodinfo    *m;
890         java_handle_t *result;
891         java_handle_t *e;
892
893         TRACEJVMCALLS(("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException));
894
895         h = (java_handle_t *) action;
896         LLNI_class_get(h, c);
897
898         if (action == NULL) {
899                 exceptions_throw_nullpointerexception();
900                 return NULL;
901         }
902
903         /* lookup run() method (throw no exceptions) */
904
905         m = class_resolveclassmethod(c, utf_run, utf_void__java_lang_Object, c,
906                                                                  false);
907
908         if ((m == NULL) || !(m->flags & ACC_PUBLIC) || (m->flags & ACC_STATIC)) {
909                 exceptions_throw_internalerror("No run method");
910                 return NULL;
911         }
912
913         /* XXX It seems something with a privileged stack needs to be done
914            here. */
915
916         result = vm_call_method(m, h);
917
918         e = exceptions_get_exception();
919
920         if (e != NULL) {
921                 if ( builtin_instanceof(e, class_java_lang_Exception) &&
922                         !builtin_instanceof(e, class_java_lang_RuntimeException)) {
923                         exceptions_clear_exception();
924                         exceptions_throw_privilegedactionexception(e);
925                 }
926
927                 return NULL;
928         }
929
930         return (jobject) result;
931 }
932
933
934 /* JVM_GetInheritedAccessControlContext */
935
936 jobject JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)
937 {
938         log_println("JVM_GetInheritedAccessControlContext: IMPLEMENT ME!");
939
940         return NULL;
941 }
942
943
944 /* JVM_GetStackAccessControlContext */
945
946 jobject JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)
947 {
948         TRACEJVMCALLS(("JVM_GetStackAccessControlContext(env=%p, cls=%p): IMPLEMENT ME!", env, cls));
949
950         /* XXX All stuff I tested so far works without that function.  At
951            some point we have to implement it, but I disable the output
952            for now to make IcedTea happy. */
953
954         return NULL;
955 }
956
957
958 /* JVM_IsArrayClass */
959
960 jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
961 {
962         classinfo *c;
963
964         TRACEJVMCALLS(("JVM_IsArrayClass(env=%p, cls=%p)", env, cls));
965
966         c = LLNI_classinfo_unwrap(cls);
967
968         return class_is_array(c);
969 }
970
971
972 /* JVM_IsPrimitiveClass */
973
974 jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
975 {
976         classinfo *c;
977
978         TRACEJVMCALLS(("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls));
979
980         c = LLNI_classinfo_unwrap(cls);
981
982         return class_is_primitive(c);
983 }
984
985
986 /* JVM_GetComponentType */
987
988 jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
989 {
990         classinfo *component;
991         classinfo *c;
992         
993         TRACEJVMCALLS(("JVM_GetComponentType(env=%p, cls=%p)", env, cls));
994
995         c = LLNI_classinfo_unwrap(cls);
996         
997         component = class_get_componenttype(c);
998
999         return (jclass) LLNI_classinfo_wrap(component);
1000 }
1001
1002
1003 /* JVM_GetClassModifiers */
1004
1005 jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
1006 {
1007         classinfo *c;
1008         int32_t    flags;
1009
1010         TRACEJVMCALLS(("JVM_GetClassModifiers(env=%p, cls=%p)", env, cls));
1011
1012         c = LLNI_classinfo_unwrap(cls);
1013
1014         flags = class_get_modifiers(c, false);
1015
1016         return flags;
1017 }
1018
1019
1020 /* JVM_GetDeclaredClasses */
1021
1022 jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
1023 {
1024         classinfo                 *c;
1025         java_handle_objectarray_t *oa;
1026
1027         TRACEJVMCALLS(("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass));
1028
1029         c = LLNI_classinfo_unwrap(ofClass);
1030
1031         oa = class_get_declaredclasses(c, false);
1032
1033         return (jobjectArray) oa;
1034 }
1035
1036
1037 /* JVM_GetDeclaringClass */
1038
1039 jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
1040 {
1041         classinfo *c;
1042         classinfo *dc;
1043
1044         TRACEJVMCALLS(("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass));
1045
1046         c = LLNI_classinfo_unwrap(ofClass);
1047
1048         dc = class_get_declaringclass(c);
1049
1050         return (jclass) LLNI_classinfo_wrap(dc);
1051 }
1052
1053
1054 /* JVM_GetClassSignature */
1055
1056 jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
1057 {
1058         classinfo     *c;
1059         utf           *u;
1060         java_handle_t *s;
1061
1062         TRACEJVMCALLS(("JVM_GetClassSignature(env=%p, cls=%p)", env, cls));
1063
1064         c = LLNI_classinfo_unwrap(cls);
1065
1066         /* Get the signature of the class. */
1067
1068         u = class_get_signature(c);
1069
1070         if (u == NULL)
1071                 return NULL;
1072
1073         /* Convert UTF-string to a Java-string. */
1074
1075         s = javastring_new(u);
1076
1077         return (jstring) s;
1078 }
1079
1080
1081 /* JVM_GetClassAnnotations */
1082
1083 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
1084 {
1085         TRACEJVMCALLS(("JVM_GetClassAnnotations(env=%p, cls=%p)", env, cls));
1086
1087         if (cls == NULL) {
1088                 exceptions_throw_nullpointerexception();
1089                 return NULL;
1090         }
1091         
1092         classinfo* c = LLNI_classinfo_unwrap(cls);
1093
1094         /* get annotations: */
1095         java_handle_bytearray_t* annotations = class_get_annotations(c);
1096
1097         return (jbyteArray) annotations;
1098 }
1099
1100
1101 /* JVM_GetFieldAnnotations */
1102
1103 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
1104 {
1105         TRACEJVMCALLS(("JVM_GetFieldAnnotations(env=%p, field=%p)", env, field));
1106
1107         java_lang_reflect_Field jlrf(field);
1108
1109         if (jlrf.is_null()) {
1110                 exceptions_throw_nullpointerexception();
1111                 return NULL;
1112         }
1113
1114         return (jbyteArray) jlrf.get_annotations();
1115 }
1116
1117
1118 /* JVM_GetMethodAnnotations */
1119
1120 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
1121 {
1122         TRACEJVMCALLS(("JVM_GetMethodAnnotations(env=%p, method=%p)", env, method));
1123
1124         java_lang_reflect_Method jlrm(method);
1125
1126         if (jlrm.is_null()) {
1127                 exceptions_throw_nullpointerexception();
1128                 return NULL;
1129         }
1130
1131         return (jbyteArray) jlrm.get_annotations();
1132 }
1133
1134
1135 /* JVM_GetMethodDefaultAnnotationValue */
1136
1137 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
1138 {
1139         TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue(env=%p, method=%p)", env, method));
1140
1141         java_lang_reflect_Method jlrm(method);
1142
1143         if (jlrm.is_null()) {
1144                 exceptions_throw_nullpointerexception();
1145                 return NULL;
1146         }
1147
1148         return (jbyteArray) jlrm.get_annotationDefault();
1149 }
1150
1151
1152 /* JVM_GetMethodParameterAnnotations */
1153
1154 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
1155 {
1156         TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations(env=%p, method=%p)", env, method));
1157
1158         java_lang_reflect_Method jlrm(method);
1159
1160         if (jlrm.is_null()) {
1161                 exceptions_throw_nullpointerexception();
1162                 return NULL;
1163         }
1164
1165         return (jbyteArray) jlrm.get_parameterAnnotations();
1166 }
1167
1168
1169 /* JVM_GetClassDeclaredFields */
1170
1171 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1172 {
1173         classinfo                 *c;
1174         java_handle_objectarray_t *oa;
1175
1176         TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1177
1178         c = LLNI_classinfo_unwrap(ofClass);
1179
1180         oa = class_get_declaredfields(c, publicOnly);
1181
1182         return (jobjectArray) oa;
1183 }
1184
1185
1186 /* JVM_GetClassDeclaredMethods */
1187
1188 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1189 {
1190         TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1191
1192         classinfo* c = LLNI_classinfo_unwrap(ofClass);
1193
1194         java_handle_objectarray_t* oa = class_get_declaredmethods(c, publicOnly);
1195
1196         return (jobjectArray) oa;
1197 }
1198
1199
1200 /* JVM_GetClassDeclaredConstructors */
1201
1202 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1203 {
1204         classinfo                 *c;
1205         java_handle_objectarray_t *oa;
1206
1207         TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1208
1209         c = LLNI_classinfo_unwrap(ofClass);
1210
1211         oa = class_get_declaredconstructors(c, publicOnly);
1212
1213         return (jobjectArray) oa;
1214 }
1215
1216
1217 /* JVM_GetClassAccessFlags */
1218
1219 jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
1220 {
1221         classinfo *c;
1222
1223         TRACEJVMCALLS(("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls));
1224
1225         c = LLNI_classinfo_unwrap(cls);
1226
1227         /* Primitive type classes have the correct access flags. */
1228
1229         return c->flags & ACC_CLASS_REFLECT_MASK;
1230 }
1231
1232
1233 /* JVM_GetClassConstantPool */
1234
1235 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
1236 {
1237 #if defined(ENABLE_ANNOTATIONS)
1238         TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
1239
1240         java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
1241         sun_reflect_ConstantPool cp(h, cls);
1242         
1243         if (cp.is_null()) {
1244                 return NULL;
1245         }
1246         
1247         return (jobject) cp.get_handle();
1248 #else
1249         log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
1250         return NULL;
1251 #endif
1252 }
1253
1254
1255 /* JVM_ConstantPoolGetSize */
1256
1257 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
1258 {
1259         classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1260
1261         TRACEJVMCALLS(("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool));
1262
1263         c = LLNI_classinfo_unwrap(jcpool);
1264
1265         return c->cpcount;
1266 }
1267
1268
1269 /* JVM_ConstantPoolGetClassAt */
1270
1271 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1272 {
1273         constant_classref *ref;    /* classref to the class at constant pool index 'index' */
1274         classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
1275         classinfo         *result; /* classinfo of the class at constant pool index 'index' */
1276
1277         TRACEJVMCALLS(("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index));
1278
1279         c = LLNI_classinfo_unwrap(jcpool);
1280
1281         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1282
1283         if (ref == NULL) {
1284                 exceptions_throw_illegalargumentexception();
1285                 return NULL;
1286         }
1287
1288         result = resolve_classref_eager(ref);
1289
1290         return (jclass) LLNI_classinfo_wrap(result);
1291 }
1292
1293
1294 /* JVM_ConstantPoolGetClassAtIfLoaded */
1295
1296 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1297 {
1298         constant_classref *ref;    /* classref to the class at constant pool index 'index' */
1299         classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
1300         classinfo         *result; /* classinfo of the class at constant pool index 'index' */
1301
1302         TRACEJVMCALLS(("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index));
1303
1304         c = LLNI_classinfo_unwrap(jcpool);
1305
1306         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1307
1308         if (ref == NULL) {
1309                 exceptions_throw_illegalargumentexception();
1310                 return NULL;
1311         }
1312         
1313         if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result)) {
1314                 return NULL;
1315         }
1316
1317         if ((result == NULL) || !(result->state & CLASS_LOADED)) {
1318                 return NULL;
1319         }
1320         
1321         return (jclass) LLNI_classinfo_wrap(result);
1322 }
1323
1324
1325 /* JVM_ConstantPoolGetMethodAt */
1326
1327 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1328 {
1329         constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1330         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1331         
1332         TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index));
1333         
1334         cls = LLNI_classinfo_unwrap(jcpool);
1335         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1336         
1337         if (ref == NULL) {
1338                 exceptions_throw_illegalargumentexception();
1339                 return NULL;
1340         }
1341
1342         // Create a new java.lang.reflect.Method Java object.
1343         /* XXX: is that right? or do I have to use resolve_method_*? */
1344         java_lang_reflect_Method jlrm(ref->p.method);
1345
1346         return (jobject) jlrm.get_handle();
1347 }
1348
1349
1350 /* JVM_ConstantPoolGetMethodAtIfLoaded */
1351
1352 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1353 {
1354         constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1355         classinfo *c = NULL;  /* resolved declaring class of the method */
1356         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1357
1358         TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1359
1360         cls = LLNI_classinfo_unwrap(jcpool);
1361         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1362
1363         if (ref == NULL) {
1364                 exceptions_throw_illegalargumentexception();
1365                 return NULL;
1366         }
1367
1368         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1369                 return NULL;
1370         }
1371
1372         if (c == NULL || !(c->state & CLASS_LOADED)) {
1373                 return NULL;
1374         }
1375
1376         // Create a new java.lang.reflect.Method Java object.
1377         java_lang_reflect_Method jlrm(ref->p.method);
1378
1379         return (jobject) jlrm.get_handle();
1380 }
1381
1382
1383 /* JVM_ConstantPoolGetFieldAt */
1384
1385 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1386 {
1387         constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1388         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1389         
1390         TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index));
1391
1392         cls = LLNI_classinfo_unwrap(jcpool);
1393         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1394
1395         if (ref == NULL) {
1396                 exceptions_throw_illegalargumentexception();
1397                 return NULL;
1398         }
1399
1400         // Create a new java.lang.reflect.Field Java object.
1401         java_lang_reflect_Field jlrf(ref->p.field);
1402
1403         return (jobject) jlrf.get_handle();
1404 }
1405
1406
1407 /* JVM_ConstantPoolGetFieldAtIfLoaded */
1408
1409 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1410 {
1411         constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1412         classinfo *c;         /* resolved declaring class for the field */
1413         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1414
1415         TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1416
1417         cls = LLNI_classinfo_unwrap(jcpool);
1418         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1419
1420         if (ref == NULL) {
1421                 exceptions_throw_illegalargumentexception();
1422                 return NULL;
1423         }
1424
1425         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1426                 return NULL;
1427         }
1428
1429         if (c == NULL || !(c->state & CLASS_LOADED)) {
1430                 return NULL;
1431         }
1432
1433         // Create a new java.lang.reflect.Field Java object.
1434         java_lang_reflect_Field jlrf(ref->p.field);
1435
1436         return (jobject) jlrf.get_handle();
1437 }
1438
1439
1440 /* JVM_ConstantPoolGetMemberRefInfoAt */
1441
1442 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1443 {
1444         log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
1445
1446         /* TODO: implement. (this is yet unused be OpenJDK but, so very low priority) */
1447
1448         return NULL;
1449 }
1450
1451
1452 /* JVM_ConstantPoolGetIntAt */
1453
1454 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1455 {
1456         constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
1457         classinfo *cls;        /* classinfo of the class for which 'this' is the constant pool */
1458
1459         TRACEJVMCALLS(("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index));
1460
1461         cls = LLNI_classinfo_unwrap(jcpool);
1462         ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
1463
1464         if (ref == NULL) {
1465                 exceptions_throw_illegalargumentexception();
1466                 return 0;
1467         }
1468
1469         return ref->value;
1470 }
1471
1472
1473 /* JVM_ConstantPoolGetLongAt */
1474
1475 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1476 {
1477         constant_long *ref; /* reference to the long value in constant pool at index 'index' */
1478         classinfo *cls;     /* classinfo of the class for which 'this' is the constant pool */
1479
1480         TRACEJVMCALLS(("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index));
1481
1482         cls = LLNI_classinfo_unwrap(jcpool);
1483         ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
1484
1485         if (ref == NULL) {
1486                 exceptions_throw_illegalargumentexception();
1487                 return 0;
1488         }
1489
1490         return ref->value;
1491 }
1492
1493
1494 /* JVM_ConstantPoolGetFloatAt */
1495
1496 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1497 {
1498         constant_float *ref; /* reference to the float value in constant pool at index 'index' */
1499         classinfo *cls;      /* classinfo of the class for which 'this' is the constant pool */
1500
1501         TRACEJVMCALLS(("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index));
1502
1503         cls = LLNI_classinfo_unwrap(jcpool);
1504         ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
1505
1506         if (ref == NULL) {
1507                 exceptions_throw_illegalargumentexception();
1508                 return 0;
1509         }
1510
1511         return ref->value;
1512 }
1513
1514
1515 /* JVM_ConstantPoolGetDoubleAt */
1516
1517 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1518 {
1519         constant_double *ref; /* reference to the double value in constant pool at index 'index' */
1520         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1521
1522         TRACEJVMCALLS(("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index));
1523
1524         cls = LLNI_classinfo_unwrap(jcpool);
1525         ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
1526
1527         if (ref == NULL) {
1528                 exceptions_throw_illegalargumentexception();
1529                 return 0;
1530         }
1531
1532         return ref->value;
1533 }
1534
1535
1536 /* JVM_ConstantPoolGetStringAt */
1537
1538 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1539 {
1540         utf *ref;       /* utf object for the string in constant pool at index 'index' */
1541         classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1542
1543         TRACEJVMCALLS(("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index));
1544         
1545         cls = LLNI_classinfo_unwrap(jcpool);
1546         ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
1547
1548         if (ref == NULL) {
1549                 exceptions_throw_illegalargumentexception();
1550                 return NULL;
1551         }
1552
1553         /* XXX: I hope literalstring_new is the right Function. */
1554         return (jstring)literalstring_new(ref);
1555 }
1556
1557
1558 /* JVM_ConstantPoolGetUTF8At */
1559
1560 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1561 {
1562         utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
1563         classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1564
1565         TRACEJVMCALLS(("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index));
1566
1567         cls = LLNI_classinfo_unwrap(jcpool);
1568         ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
1569
1570         if (ref == NULL) {
1571                 exceptions_throw_illegalargumentexception();
1572                 return NULL;
1573         }
1574
1575         /* XXX: I hope literalstring_new is the right Function. */
1576         return (jstring)literalstring_new(ref);
1577 }
1578
1579
1580 /* JVM_DesiredAssertionStatus */
1581
1582 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
1583 {
1584 #if defined(ENABLE_ASSERTION)
1585         classinfo         *c;
1586         jboolean           status;
1587         utf               *name;
1588
1589         TRACEJVMCALLS(("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls));
1590
1591         c = LLNI_classinfo_unwrap(cls);
1592
1593         if (c->classloader == NULL) {
1594                 status = (jboolean)assertion_system_enabled;
1595         }
1596         else {
1597                 status = (jboolean)assertion_user_enabled;
1598         }
1599
1600         if (list_assertion_names != NULL) {
1601                 for (List<assertion_name_t*>::iterator it = list_assertion_names->begin();
1602                          it != list_assertion_names->end(); it++) {
1603                         assertion_name_t* item = *it;
1604
1605                         name = utf_new_char(item->name);
1606                         if (name == c->packagename) {
1607                                 status = (jboolean)item->enabled;
1608                         }
1609                         else if (name == c->name) {
1610                                 status = (jboolean)item->enabled;
1611                         }
1612                 }
1613         }
1614
1615         return status;
1616 #else
1617         return (jboolean)false;
1618 #endif
1619 }
1620
1621
1622 /* JVM_AssertionStatusDirectives */
1623
1624 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
1625 {
1626         java_handle_objectarray_t             *classes;
1627         java_handle_objectarray_t             *packages;
1628         java_booleanarray_t                   *classEnabled;
1629         java_booleanarray_t                   *packageEnabled;
1630 #if defined(ENABLE_ASSERTION)
1631         java_handle_t                         *js;
1632         s4                                     i, j;
1633 #endif
1634
1635         TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
1636
1637 #if defined(ENABLE_ASSERTION)
1638         classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
1639 #else
1640         classes = builtin_anewarray(0, class_java_lang_Object);
1641 #endif
1642         if (classes == NULL)
1643                 return NULL;
1644
1645 #if defined(ENABLE_ASSERTION)
1646         packages = builtin_anewarray(assertion_package_count, class_java_lang_Object);
1647 #else
1648         packages = builtin_anewarray(0, class_java_lang_Object);
1649 #endif
1650         if (packages == NULL)
1651                 return NULL;
1652         
1653 #if defined(ENABLE_ASSERTION)
1654         classEnabled = builtin_newarray_boolean(assertion_class_count);
1655 #else
1656         classEnabled = builtin_newarray_boolean(0);
1657 #endif
1658         if (classEnabled == NULL)
1659                 return NULL;
1660
1661 #if defined(ENABLE_ASSERTION)
1662         packageEnabled = builtin_newarray_boolean(assertion_package_count);
1663 #else
1664         packageEnabled = builtin_newarray_boolean(0);
1665 #endif
1666         if (packageEnabled == NULL)
1667                 return NULL;
1668
1669 #if defined(ENABLE_ASSERTION)
1670         /* initialize arrays */
1671
1672         if (list_assertion_names != NULL) {
1673                 i = 0;
1674                 j = 0;
1675                 
1676                 for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
1677                         assertion_name_t* item = *it;
1678
1679                         js = javastring_new_from_ascii(item->name);
1680                         if (js == NULL) {
1681                                 return NULL;
1682                         }
1683
1684                         if (item->package == false) {
1685                                 classes->data[i] = js;
1686                                 classEnabled->data[i] = (jboolean) item->enabled;
1687                                 i += 1;
1688                         }
1689                         else {
1690                                 packages->data[j] = js;
1691                                 packageEnabled->data[j] = (jboolean) item->enabled;
1692                                 j += 1;
1693                         }
1694                 }
1695         }
1696 #endif
1697
1698         /* set instance fields */
1699
1700         java_lang_AssertionStatusDirectives jlasd(classes, classEnabled, packages, packageEnabled);
1701
1702         return (jobject) jlasd.get_handle();
1703 }
1704
1705
1706 /* JVM_GetClassNameUTF */
1707
1708 const char *JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
1709 {
1710         log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
1711
1712         return NULL;
1713 }
1714
1715
1716 /* JVM_GetClassCPTypes */
1717
1718 void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
1719 {
1720         log_println("JVM_GetClassCPTypes: IMPLEMENT ME!");
1721 }
1722
1723
1724 /* JVM_GetClassCPEntriesCount */
1725
1726 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
1727 {
1728         log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
1729
1730         return 0;
1731 }
1732
1733
1734 /* JVM_GetClassFieldsCount */
1735
1736 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
1737 {
1738         log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
1739
1740         return 0;
1741 }
1742
1743
1744 /* JVM_GetClassMethodsCount */
1745
1746 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
1747 {
1748         log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
1749
1750         return 0;
1751 }
1752
1753
1754 /* JVM_GetMethodIxExceptionIndexes */
1755
1756 void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)
1757 {
1758         log_println("JVM_GetMethodIxExceptionIndexes: IMPLEMENT ME!");
1759 }
1760
1761
1762 /* JVM_GetMethodIxExceptionsCount */
1763
1764 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
1765 {
1766         log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
1767
1768         return 0;
1769 }
1770
1771
1772 /* JVM_GetMethodIxByteCode */
1773
1774 void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)
1775 {
1776         log_println("JVM_GetMethodIxByteCode: IMPLEMENT ME!");
1777 }
1778
1779
1780 /* JVM_GetMethodIxByteCodeLength */
1781
1782 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
1783 {
1784         log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
1785
1786         return 0;
1787 }
1788
1789
1790 /* JVM_GetMethodIxExceptionTableEntry */
1791
1792 void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)
1793 {
1794         log_println("JVM_GetMethodIxExceptionTableEntry: IMPLEMENT ME!");
1795 }
1796
1797
1798 /* JVM_GetMethodIxExceptionTableLength */
1799
1800 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
1801 {
1802         log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
1803
1804         return 0;
1805 }
1806
1807
1808 /* JVM_GetMethodIxModifiers */
1809
1810 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
1811 {
1812         log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
1813
1814         return 0;
1815 }
1816
1817
1818 /* JVM_GetFieldIxModifiers */
1819
1820 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
1821 {
1822         log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
1823
1824         return 0;
1825 }
1826
1827
1828 /* JVM_GetMethodIxLocalsCount */
1829
1830 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
1831 {
1832         log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
1833
1834         return 0;
1835 }
1836
1837
1838 /* JVM_GetMethodIxArgsSize */
1839
1840 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
1841 {
1842         log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
1843
1844         return 0;
1845 }
1846
1847
1848 /* JVM_GetMethodIxMaxStack */
1849
1850 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
1851 {
1852         log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
1853
1854         return 0;
1855 }
1856
1857
1858 /* JVM_IsConstructorIx */
1859
1860 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
1861 {
1862         log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
1863
1864         return 0;
1865 }
1866
1867
1868 /* JVM_GetMethodIxNameUTF */
1869
1870 const char *JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
1871 {
1872         log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
1873
1874         return NULL;
1875 }
1876
1877
1878 /* JVM_GetMethodIxSignatureUTF */
1879
1880 const char *JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
1881 {
1882         log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
1883
1884         return NULL;
1885 }
1886
1887
1888 /* JVM_GetCPFieldNameUTF */
1889
1890 const char *JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1891 {
1892         log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
1893
1894         return NULL;
1895 }
1896
1897
1898 /* JVM_GetCPMethodNameUTF */
1899
1900 const char *JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1901 {
1902         log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
1903
1904         return NULL;
1905 }
1906
1907
1908 /* JVM_GetCPMethodSignatureUTF */
1909
1910 const char *JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1911 {
1912         log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
1913
1914         return NULL;
1915 }
1916
1917
1918 /* JVM_GetCPFieldSignatureUTF */
1919
1920 const char *JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1921 {
1922         log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
1923
1924         return NULL;
1925 }
1926
1927
1928 /* JVM_GetCPClassNameUTF */
1929
1930 const char *JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1931 {
1932         log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
1933
1934         return NULL;
1935 }
1936
1937
1938 /* JVM_GetCPFieldClassNameUTF */
1939
1940 const char *JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1941 {
1942         log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
1943
1944         return NULL;
1945 }
1946
1947
1948 /* JVM_GetCPMethodClassNameUTF */
1949
1950 const char *JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1951 {
1952         log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
1953
1954         return NULL;
1955 }
1956
1957
1958 /* JVM_GetCPFieldModifiers */
1959
1960 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1961 {
1962         log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
1963
1964         return 0;
1965 }
1966
1967
1968 /* JVM_GetCPMethodModifiers */
1969
1970 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
1971 {
1972         log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
1973
1974         return 0;
1975 }
1976
1977
1978 /* JVM_ReleaseUTF */
1979
1980 void JVM_ReleaseUTF(const char *utf)
1981 {
1982         log_println("JVM_ReleaseUTF: IMPLEMENT ME!");
1983 }
1984
1985
1986 /* JVM_IsSameClassPackage */
1987
1988 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
1989 {
1990         log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
1991
1992         return 0;
1993 }
1994
1995
1996 /* JVM_Open */
1997
1998 /* Taken from: hotspot/src/share/vm/prims/jvm.h */
1999
2000 /*
2001  * JVM I/O error codes
2002  */
2003 #define JVM_EEXIST       -100
2004
2005 jint JVM_Open(const char* fname, jint flags, jint mode)
2006 {
2007         int result;
2008
2009         TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
2010
2011         HPI& hpi = VM::get_current()->get_hpi();
2012         result = hpi.get_file().Open(fname, flags, mode);
2013
2014         if (result >= 0) {
2015                 return result;
2016         }
2017         else {
2018                 switch (errno) {
2019                 case EEXIST:
2020                         return JVM_EEXIST;
2021                 default:
2022                         return -1;
2023                 }
2024         }
2025 }
2026
2027
2028 /* JVM_Close */
2029
2030 jint JVM_Close(jint fd)
2031 {
2032         TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
2033
2034         HPI& hpi = VM::get_current()->get_hpi();
2035         return hpi.get_file().Close(fd);
2036 }
2037
2038
2039 /* JVM_Read */
2040
2041 jint JVM_Read(jint fd, char* buf, jint nbytes)
2042 {
2043         TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
2044
2045         HPI& hpi = VM::get_current()->get_hpi();
2046         return (jint) hpi.get_file().Read(fd, buf, nbytes);
2047 }
2048
2049
2050 /* JVM_Write */
2051
2052 jint JVM_Write(jint fd, char* buf, jint nbytes)
2053 {
2054         TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
2055
2056         HPI& hpi = VM::get_current()->get_hpi();
2057         return (jint) hpi.get_file().Write(fd, buf, nbytes);
2058 }
2059
2060
2061 /* JVM_Available */
2062
2063 jint JVM_Available(jint fd, jlong* pbytes)
2064 {
2065         TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
2066
2067         HPI& hpi = VM::get_current()->get_hpi();
2068         return hpi.get_file().Available(fd, pbytes);
2069 }
2070
2071
2072 /* JVM_Lseek */
2073
2074 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
2075 {
2076         TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
2077
2078         HPI& hpi = VM::get_current()->get_hpi();
2079         return hpi.get_file().Seek(fd, (off_t) offset, whence);
2080 }
2081
2082
2083 /* JVM_SetLength */
2084
2085 jint JVM_SetLength(jint fd, jlong length)
2086 {
2087         TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
2088
2089         HPI& hpi = VM::get_current()->get_hpi();
2090         return hpi.get_file().SetLength(fd, length);
2091 }
2092
2093
2094 /* JVM_Sync */
2095
2096 jint JVM_Sync(jint fd)
2097 {
2098         TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
2099
2100         HPI& hpi = VM::get_current()->get_hpi();
2101         return hpi.get_file().Sync(fd);
2102 }
2103
2104
2105 /* JVM_StartThread */
2106
2107 void JVM_StartThread(JNIEnv* env, jobject jthread)
2108 {
2109         TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
2110
2111         threads_thread_start((java_handle_t *) jthread);
2112 }
2113
2114
2115 /* JVM_StopThread */
2116
2117 void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
2118 {
2119         log_println("JVM_StopThread: Deprecated.  Not implemented.");
2120 }
2121
2122
2123 /* JVM_IsThreadAlive */
2124
2125 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
2126 {
2127         java_handle_t *h;
2128         threadobject  *t;
2129         bool           result;
2130
2131         TRACEJVMCALLS(("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread));
2132
2133         h = (java_handle_t *) jthread;
2134         t = thread_get_thread(h);
2135
2136         /* The threadobject is null when a thread is created in Java. The
2137            priority is set later during startup. */
2138
2139         if (t == NULL)
2140                 return 0;
2141
2142         result = threads_thread_is_alive(t);
2143
2144         return result;
2145 }
2146
2147
2148 /* JVM_SuspendThread */
2149
2150 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
2151 {
2152         log_println("JVM_SuspendThread: Deprecated.  Not implemented.");
2153 }
2154
2155
2156 /* JVM_ResumeThread */
2157
2158 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
2159 {
2160         log_println("JVM_ResumeThread: Deprecated.  Not implemented.");
2161 }
2162
2163
2164 /* JVM_SetThreadPriority */
2165
2166 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
2167 {
2168         java_handle_t *h;
2169         threadobject  *t;
2170
2171         TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
2172
2173         h = (java_handle_t *) jthread;
2174         t = thread_get_thread(h);
2175
2176         /* The threadobject is null when a thread is created in Java. The
2177            priority is set later during startup. */
2178
2179         if (t == NULL)
2180                 return;
2181
2182         threads_set_thread_priority(t->tid, prio);
2183 }
2184
2185
2186 /* JVM_Yield */
2187
2188 void JVM_Yield(JNIEnv *env, jclass threadClass)
2189 {
2190         TRACEJVMCALLS(("JVM_Yield(env=%p, threadClass=%p)", env, threadClass));
2191
2192         threads_yield();
2193 }
2194
2195
2196 /* JVM_Sleep */
2197
2198 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
2199 {
2200         TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
2201
2202         threads_sleep(millis, 0);
2203 }
2204
2205
2206 /* JVM_CurrentThread */
2207
2208 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
2209 {
2210         java_object_t *o;
2211
2212         TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
2213
2214         o = thread_get_current_object();
2215
2216         return (jobject) o;
2217 }
2218
2219
2220 /* JVM_CountStackFrames */
2221
2222 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
2223 {
2224         log_println("JVM_CountStackFrames: Deprecated.  Not implemented.");
2225
2226         return 0;
2227 }
2228
2229
2230 /* JVM_Interrupt */
2231
2232 void JVM_Interrupt(JNIEnv* env, jobject jthread)
2233 {
2234         java_handle_t *h;
2235         threadobject  *t;
2236
2237         TRACEJVMCALLS(("JVM_Interrupt(env=%p, jthread=%p)", env, jthread));
2238
2239         h = (java_handle_t *) jthread;
2240         t = thread_get_thread(h);
2241
2242         if (t == NULL)
2243                 return;
2244
2245         threads_thread_interrupt(t);
2246 }
2247
2248
2249 /* JVM_IsInterrupted */
2250
2251 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2252 {
2253         java_handle_t *h;
2254         threadobject  *t;
2255         jboolean       interrupted;
2256
2257         TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
2258
2259         h = (java_handle_t *) jthread;
2260         t = thread_get_thread(h);
2261
2262         interrupted = thread_is_interrupted(t);
2263
2264         if (interrupted && clear_interrupted)
2265                 thread_set_interrupted(t, false);
2266
2267         return interrupted;
2268 }
2269
2270
2271 /* JVM_HoldsLock */
2272
2273 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2274 {
2275         java_handle_t *h;
2276         bool           result;
2277
2278         TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
2279
2280         h = (java_handle_t *) obj;
2281
2282         if (h == NULL) {
2283                 exceptions_throw_nullpointerexception();
2284                 return JNI_FALSE;
2285         }
2286
2287         result = lock_is_held_by_current_thread(h);
2288
2289         return result;
2290 }
2291
2292
2293 /* JVM_DumpAllStacks */
2294
2295 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2296 {
2297         log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2298 }
2299
2300
2301 /* JVM_CurrentLoadedClass */
2302
2303 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2304 {
2305         log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2306
2307         return NULL;
2308 }
2309
2310
2311 /* JVM_CurrentClassLoader */
2312
2313 jobject JVM_CurrentClassLoader(JNIEnv *env)
2314 {
2315     /* XXX if a method in a class in a trusted loader is in a
2316            doPrivileged, return NULL */
2317
2318         log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2319
2320         return NULL;
2321 }
2322
2323
2324 /* JVM_GetClassContext */
2325
2326 jobjectArray JVM_GetClassContext(JNIEnv *env)
2327 {
2328         TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
2329
2330         return (jobjectArray) stacktrace_getClassContext();
2331 }
2332
2333
2334 /* JVM_ClassDepth */
2335
2336 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2337 {
2338         log_println("JVM_ClassDepth: IMPLEMENT ME!");
2339
2340         return 0;
2341 }
2342
2343
2344 /* JVM_ClassLoaderDepth */
2345
2346 jint JVM_ClassLoaderDepth(JNIEnv *env)
2347 {
2348         log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2349
2350         return 0;
2351 }
2352
2353
2354 /* JVM_GetSystemPackage */
2355
2356 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2357 {
2358         java_handle_t *s;
2359         utf *u;
2360         utf *result;
2361
2362         TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
2363
2364 /*      s = Package::find(name); */
2365         u = javastring_toutf((java_handle_t *) name, false);
2366
2367         result = Package::find(u);
2368
2369         if (result != NULL)
2370                 s = javastring_new(result);
2371         else
2372                 s = NULL;
2373
2374         return (jstring) s;
2375 }
2376
2377
2378 /* JVM_GetSystemPackages */
2379
2380 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2381 {
2382         log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2383
2384         return NULL;
2385 }
2386
2387
2388 /* JVM_AllocateNewObject */
2389
2390 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2391 {
2392         log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2393
2394         return NULL;
2395 }
2396
2397
2398 /* JVM_AllocateNewArray */
2399
2400 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2401 {
2402         log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2403
2404         return NULL;
2405 }
2406
2407
2408 /* JVM_LatestUserDefinedLoader */
2409
2410 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2411 {
2412         classloader_t *cl;
2413
2414         TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
2415
2416         cl = stacktrace_first_nonnull_classloader();
2417
2418         return (jobject) cl;
2419 }
2420
2421
2422 /* JVM_LoadClass0 */
2423
2424 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2425 {
2426         log_println("JVM_LoadClass0: IMPLEMENT ME!");
2427
2428         return NULL;
2429 }
2430
2431
2432 /* JVM_GetArrayLength */
2433
2434 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2435 {
2436         java_handle_t *a;
2437
2438         TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
2439
2440         a = (java_handle_t *) arr;
2441
2442         return array_length_get(a);
2443 }
2444
2445
2446 /* JVM_GetArrayElement */
2447
2448 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2449 {
2450         java_handle_t *a;
2451         java_handle_t *o;
2452
2453         TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
2454
2455         a = (java_handle_t *) arr;
2456
2457 /*      if (!class_is_array(a->objheader.vftbl->class)) { */
2458 /*              exceptions_throw_illegalargumentexception(); */
2459 /*              return NULL; */
2460 /*      } */
2461
2462         o = array_element_get(a, index);
2463
2464         return (jobject) o;
2465 }
2466
2467
2468 /* JVM_GetPrimitiveArrayElement */
2469
2470 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2471 {
2472         jvalue jv;
2473
2474         log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2475
2476         jv.l = NULL;
2477
2478         return jv;
2479 }
2480
2481
2482 /* JVM_SetArrayElement */
2483
2484 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2485 {
2486         java_handle_t *a;
2487         java_handle_t *value;
2488
2489         TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
2490
2491         a     = (java_handle_t *) arr;
2492         value = (java_handle_t *) val;
2493
2494         array_element_set(a, index, value);
2495 }
2496
2497
2498 /* JVM_SetPrimitiveArrayElement */
2499
2500 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2501 {
2502         log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2503 }
2504
2505
2506 /* JVM_NewArray */
2507
2508 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2509 {
2510         classinfo                 *c;
2511         classinfo                 *pc;
2512         java_handle_t             *a;
2513         java_handle_objectarray_t *oa;
2514
2515         TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
2516
2517         if (eltClass == NULL) {
2518                 exceptions_throw_nullpointerexception();
2519                 return NULL;
2520         }
2521
2522         /* NegativeArraySizeException is checked in builtin_newarray. */
2523
2524         c = LLNI_classinfo_unwrap(eltClass);
2525
2526         /* Create primitive or object array. */
2527
2528         if (class_is_primitive(c)) {
2529                 pc = Primitive::get_arrayclass_by_name(c->name);
2530
2531                 /* void arrays are not allowed. */
2532
2533                 if (pc == NULL) {
2534                         exceptions_throw_illegalargumentexception();
2535                         return NULL;
2536                 }
2537
2538                 a = builtin_newarray(length, pc);
2539
2540                 return (jobject) a;
2541         }
2542         else {
2543                 oa = builtin_anewarray(length, c);
2544
2545                 return (jobject) oa;
2546         }
2547 }
2548
2549
2550 /* JVM_NewMultiArray */
2551
2552 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2553 {
2554         classinfo                 *c;
2555         java_handle_intarray_t    *ia;
2556         int32_t                    length;
2557         long                      *dims;
2558         int32_t                    value;
2559         int32_t                    i;
2560         classinfo                 *ac;
2561         java_handle_objectarray_t *a;
2562
2563         TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
2564
2565         if (eltClass == NULL) {
2566                 exceptions_throw_nullpointerexception();
2567                 return NULL;
2568         }
2569
2570         /* NegativeArraySizeException is checked in builtin_newarray. */
2571
2572         c = LLNI_classinfo_unwrap(eltClass);
2573
2574         ia = (java_handle_intarray_t *) dim;
2575
2576         length = array_length_get((java_handle_t *) ia);
2577
2578         /* We check here for exceptions thrown in array_length_get,
2579            otherwise these exceptions get overwritten by the following
2580            IllegalArgumentException. */
2581
2582         if (length < 0)
2583                 return NULL;
2584
2585         if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
2586                 exceptions_throw_illegalargumentexception();
2587                 return NULL;
2588         }
2589
2590         /* XXX This is just a quick hack to get it working. */
2591
2592         dims = MNEW(long, length);
2593
2594         for (i = 0; i < length; i++) {
2595                 value = LLNI_array_direct(ia, i);
2596                 dims[i] = (long) value;
2597         }
2598
2599         /* Create an array-class if necessary. */
2600
2601         if (class_is_primitive(c)) {
2602                 ac = Primitive::get_arrayclass_by_name(c->name);
2603
2604                 // Arrays of void are not allowed.
2605                 if (ac == NULL) {
2606                         exceptions_throw_illegalargumentexception();
2607                         return NULL;
2608                 }
2609
2610                 if (length > 1)
2611                         ac = class_multiarray_of((length - 1), ac, true);
2612         }
2613         else
2614                 ac = class_multiarray_of(length, c, true);
2615
2616         if (ac == NULL)
2617                 return NULL;
2618
2619         /* Allocate a new array on the heap. */
2620
2621         a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
2622
2623         return (jobject) a;
2624 }
2625
2626
2627 /* JVM_InitializeSocketLibrary */
2628
2629 jint JVM_InitializeSocketLibrary()
2630 {
2631         TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
2632
2633         HPI& hpi = VM::get_current()->get_hpi();
2634         return hpi.initialize_socket_library();
2635 }
2636
2637
2638 /* JVM_Socket */
2639
2640 jint JVM_Socket(jint domain, jint type, jint protocol)
2641 {
2642         TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
2643
2644         return os::socket(domain, type, protocol);
2645 }
2646
2647
2648 /* JVM_SocketClose */
2649
2650 jint JVM_SocketClose(jint fd)
2651 {
2652         TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
2653
2654         return os::close(fd);
2655 }
2656
2657
2658 /* JVM_SocketShutdown */
2659
2660 jint JVM_SocketShutdown(jint fd, jint howto)
2661 {
2662         TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
2663
2664         return os::shutdown(fd, howto);
2665 }
2666
2667
2668 /* JVM_Recv */
2669
2670 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2671 {
2672         log_println("JVM_Recv: IMPLEMENT ME!");
2673
2674         return 0;
2675 }
2676
2677
2678 /* JVM_Send */
2679
2680 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2681 {
2682         TRACEJVMCALLSENTER(("JVM_Send(fd=%d, buf=%p, nBytes=%d, flags=%d", fd, buf, nBytes, flags));
2683
2684         int result = os::send(fd, buf, nBytes, flags);
2685
2686         TRACEJVMCALLSEXIT(("->%d", result));
2687
2688         return result;
2689 }
2690
2691
2692 /* JVM_Timeout */
2693
2694 jint JVM_Timeout(int fd, long timeout)
2695 {
2696         log_println("JVM_Timeout: IMPLEMENT ME!");
2697
2698         return 0;
2699 }
2700
2701
2702 /* JVM_Listen */
2703
2704 jint JVM_Listen(jint fd, jint count)
2705 {
2706         TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
2707
2708         return os::listen(fd, count);
2709 }
2710
2711
2712 /* JVM_Connect */
2713
2714 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2715 {
2716         TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
2717
2718         return os::connect(fd, him, len);
2719 }
2720
2721
2722 /* JVM_Bind */
2723
2724 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2725 {
2726         log_println("JVM_Bind: IMPLEMENT ME!");
2727
2728         return 0;
2729 }
2730
2731
2732 /* JVM_Accept */
2733
2734 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2735 {
2736         TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
2737
2738         return os::accept(fd, him, (socklen_t *) len);
2739 }
2740
2741
2742 /* JVM_RecvFrom */
2743
2744 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2745 {
2746         log_println("JVM_RecvFrom: IMPLEMENT ME!");
2747
2748         return 0;
2749 }
2750
2751
2752 /* JVM_GetSockName */
2753
2754 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2755 {
2756         TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
2757
2758         return os::getsockname(fd, him, (socklen_t *) len);
2759 }
2760
2761
2762 /* JVM_SendTo */
2763
2764 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2765 {
2766         log_println("JVM_SendTo: IMPLEMENT ME!");
2767
2768         return 0;
2769 }
2770
2771
2772 /* JVM_SocketAvailable */
2773
2774 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2775 {
2776 #if defined(FIONREAD)
2777         int bytes;
2778         int result;
2779
2780         TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
2781
2782         *pbytes = 0;
2783
2784         result = ioctl(fd, FIONREAD, &bytes);
2785
2786         if (result < 0)
2787                 return 0;
2788
2789         *pbytes = bytes;
2790
2791         return 1;
2792 #else
2793 # error FIONREAD not defined
2794 #endif
2795 }
2796
2797
2798 /* JVM_GetSockOpt */
2799
2800 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2801 {
2802         TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
2803
2804         return os::getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
2805 }
2806
2807
2808 /* JVM_SetSockOpt */
2809
2810 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2811 {
2812         TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
2813
2814         return os::setsockopt(fd, level, optname, optval, optlen);
2815 }
2816
2817
2818 /* JVM_GetHostName */
2819
2820 int JVM_GetHostName(char *name, int namelen)
2821 {
2822         int result;
2823
2824         TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
2825
2826         result = os::gethostname(name, namelen);
2827
2828         TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
2829
2830         return result;
2831 }
2832
2833
2834 /* JVM_GetHostByAddr */
2835
2836 struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
2837 {
2838         log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2839
2840         return NULL;
2841 }
2842
2843
2844 /* JVM_GetHostByName */
2845
2846 struct hostent *JVM_GetHostByName(char* name)
2847 {
2848         log_println("JVM_GetHostByName: IMPLEMENT ME!");
2849
2850         return NULL;
2851 }
2852
2853
2854 /* JVM_GetProtoByName */
2855
2856 struct protoent *JVM_GetProtoByName(char* name)
2857 {
2858         log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2859
2860         return NULL;
2861 }
2862
2863
2864 /* JVM_LoadLibrary */
2865
2866 void* JVM_LoadLibrary(const char* name)
2867 {
2868         TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
2869
2870         utf* u = utf_new_char(name);
2871
2872         NativeLibrary nl(u);
2873         void* handle = nl.open();
2874         
2875         TRACEJVMCALLSEXIT(("->%p", handle));
2876
2877         return handle;
2878 }
2879
2880
2881 /* JVM_UnloadLibrary */
2882
2883 void JVM_UnloadLibrary(void* handle)
2884 {
2885         TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
2886
2887         NativeLibrary nl(handle);
2888         nl.close();
2889 }
2890
2891
2892 /* JVM_FindLibraryEntry */
2893
2894 void *JVM_FindLibraryEntry(void* handle, const char* name)
2895 {
2896         void* symbol;
2897
2898         TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
2899
2900         HPI& hpi = VM::get_current()->get_hpi();
2901         symbol = hpi.get_library().FindLibraryEntry(handle, name);
2902
2903         TRACEJVMCALLSEXIT(("->%p", symbol));
2904
2905         return symbol;
2906 }
2907
2908
2909 /* JVM_IsNaN */
2910
2911 jboolean JVM_IsNaN(jdouble d)
2912 {
2913         bool result;
2914
2915         TRACEJVMCALLSENTER(("JVM_IsNaN(d=%f)", d));
2916
2917         result = isnan(d);
2918
2919         TRACEJVMCALLSEXIT(("->%d", result));
2920
2921         return result;
2922 }
2923
2924
2925 /* JVM_IsSupportedJNIVersion */
2926
2927 jboolean JVM_IsSupportedJNIVersion(jint version)
2928 {
2929         TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
2930
2931         return jni_version_check(version);
2932 }
2933
2934
2935 /* JVM_InternString */
2936
2937 jstring JVM_InternString(JNIEnv *env, jstring str)
2938 {
2939         TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
2940
2941         return (jstring) javastring_intern((java_handle_t *) str);
2942 }
2943
2944
2945 /* JVM_RawMonitorCreate */
2946
2947 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
2948 {
2949         TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
2950
2951         Mutex* m = new Mutex();
2952
2953         return m;
2954 }
2955
2956
2957 /* JVM_RawMonitorDestroy */
2958
2959 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void* mon)
2960 {
2961         TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
2962
2963         delete ((Mutex*) mon);
2964 }
2965
2966
2967 /* JVM_RawMonitorEnter */
2968
2969 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void* mon)
2970 {
2971         TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
2972
2973         ((Mutex*) mon)->lock();
2974
2975         return 0;
2976 }
2977
2978
2979 /* JVM_RawMonitorExit */
2980
2981 JNIEXPORT void JNICALL JVM_RawMonitorExit(void* mon)
2982 {
2983         TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
2984
2985         ((Mutex*) mon)->unlock();
2986 }
2987
2988
2989 /* JVM_SetPrimitiveFieldValues */
2990
2991 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
2992 {
2993         log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
2994 }
2995
2996
2997 /* JVM_GetPrimitiveFieldValues */
2998
2999 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3000 {
3001         log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
3002 }
3003
3004
3005 /* JVM_AccessVMBooleanFlag */
3006
3007 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
3008 {
3009         log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
3010
3011         return 0;
3012 }
3013
3014
3015 /* JVM_AccessVMIntFlag */
3016
3017 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
3018 {
3019         log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
3020
3021         return 0;
3022 }
3023
3024
3025 /* JVM_VMBreakPoint */
3026
3027 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
3028 {
3029         log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
3030 }
3031
3032
3033 /* JVM_GetClassFields */
3034
3035 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
3036 {
3037         log_println("JVM_GetClassFields: IMPLEMENT ME!");
3038
3039         return NULL;
3040 }
3041
3042
3043 /* JVM_GetClassMethods */
3044
3045 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
3046 {
3047         log_println("JVM_GetClassMethods: IMPLEMENT ME!");
3048
3049         return NULL;
3050 }
3051
3052
3053 /* JVM_GetClassConstructors */
3054
3055 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
3056 {
3057         log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
3058
3059         return NULL;
3060 }
3061
3062
3063 /* JVM_GetClassField */
3064
3065 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
3066 {
3067         log_println("JVM_GetClassField: IMPLEMENT ME!");
3068
3069         return NULL;
3070 }
3071
3072
3073 /* JVM_GetClassMethod */
3074
3075 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
3076 {
3077         log_println("JVM_GetClassMethod: IMPLEMENT ME!");
3078
3079         return NULL;
3080 }
3081
3082
3083 /* JVM_GetClassConstructor */
3084
3085 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
3086 {
3087         log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
3088
3089         return NULL;
3090 }
3091
3092
3093 /* JVM_NewInstance */
3094
3095 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
3096 {
3097         log_println("JVM_NewInstance: IMPLEMENT ME!");
3098
3099         return NULL;
3100 }
3101
3102
3103 /* JVM_GetField */
3104
3105 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
3106 {
3107         log_println("JVM_GetField: IMPLEMENT ME!");
3108
3109         return NULL;
3110 }
3111
3112
3113 /* JVM_GetPrimitiveField */
3114
3115 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
3116 {
3117         jvalue jv;
3118
3119         log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
3120
3121         jv.l = NULL;
3122
3123         return jv;
3124 }
3125
3126
3127 /* JVM_SetField */
3128
3129 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
3130 {
3131         log_println("JVM_SetField: IMPLEMENT ME!");
3132 }
3133
3134
3135 /* JVM_SetPrimitiveField */
3136
3137 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
3138 {
3139         log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
3140 }
3141
3142
3143 /* JVM_InvokeMethod */
3144
3145 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
3146 {
3147         TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
3148
3149         java_lang_reflect_Method jlrm(method);
3150         
3151         java_handle_t* result = jlrm.invoke((java_handle_t*) obj, (java_handle_objectarray_t*) args0);
3152
3153         return (jobject) result;
3154 }
3155
3156
3157 /* JVM_NewInstanceFromConstructor */
3158
3159 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
3160 {
3161         TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
3162
3163         java_lang_reflect_Constructor jlrc(con);
3164         java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args0);
3165
3166         return (jobject) o;
3167 }
3168
3169
3170 /* JVM_SupportsCX8 */
3171
3172 jboolean JVM_SupportsCX8()
3173 {
3174         TRACEJVMCALLS(("JVM_SupportsCX8()"));
3175
3176         /* IMPLEMENT ME */
3177
3178         return 0;
3179 }
3180
3181
3182 /* JVM_CX8Field */
3183
3184 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
3185 {
3186         log_println("JVM_CX8Field: IMPLEMENT ME!");
3187
3188         return 0;
3189 }
3190
3191
3192 /* JVM_GetAllThreads */
3193
3194 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
3195 {
3196         // Get a list of all active threads.
3197         list<threadobject*> active_threads;
3198         ThreadList::get_active_threads(active_threads);
3199
3200         // Allocate array to hold the java.lang.Thread objects.
3201         int32_t length = active_threads.size();
3202         java_handle_objectarray_t* oa = builtin_anewarray(length, class_java_lang_Thread);
3203
3204         if (oa == NULL)
3205                 return NULL;
3206
3207         // Iterate over all threads (which were active just a second ago).
3208         int32_t index = 0;
3209         for (List<threadobject*>::iterator it = active_threads.begin(); it != active_threads.end(); it++) {
3210                 threadobject* t = *it;
3211
3212                 java_handle_t* h = thread_get_object(t);
3213                 assert(h != NULL);
3214
3215                 array_objectarray_element_set(oa, index, h);
3216
3217                 index++;
3218         }
3219
3220         return oa;
3221 }
3222
3223
3224 /* JVM_DumpThreads */
3225
3226 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
3227 {
3228         int32_t i;
3229
3230         TRACEJVMCALLS(("JVM_DumpThreads((env=%p, threadClass=%p, threads=%p)", env, threadClass, threads));
3231
3232         if (threads == NULL) {
3233                 exceptions_throw_nullpointerexception();
3234                 return NULL;
3235         }
3236
3237         // Get length of the threads array.
3238         int32_t length = array_length_get((java_handle_t*) threads);
3239
3240         if (length <= 0) {
3241                 exceptions_throw_illegalargumentexception();
3242                 return NULL;
3243         }
3244
3245         // Allocate array to hold stacktraces.
3246         classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
3247         java_handle_objectarray_t* oas = builtin_anewarray(length, arrayclass);
3248
3249         if (oas == NULL) {
3250                 return NULL;
3251         }
3252
3253         // Iterate over all passed thread objects.
3254         for (i = 0; i < length; i++) {
3255                 java_handle_t* thread = array_objectarray_element_get(threads, i);
3256
3257                 // Get thread for the given thread object.
3258                 threadobject* t = thread_get_thread(thread);
3259
3260                 if (t == NULL)
3261                         continue;
3262
3263                 // Get stacktrace for given thread.
3264                 stacktrace_t* st = stacktrace_get_of_thread(t);
3265
3266                 // Convert stacktrace into array of StackTraceElements.
3267                 java_handle_objectarray_t* oa = stacktrace_get_StackTraceElements(st);
3268
3269                 if (oa == NULL)
3270                         return NULL;
3271
3272                 array_objectarray_element_set(oas, i, (java_handle_t*) oa);
3273         }
3274
3275         return oas;
3276 }
3277
3278
3279 /* JVM_GetManagement */
3280
3281 void *JVM_GetManagement(jint version)
3282 {
3283         TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
3284
3285         return Management::get_jmm_interface(version);
3286 }
3287
3288
3289 /* JVM_InitAgentProperties */
3290
3291 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
3292 {
3293         log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
3294
3295         return NULL;
3296 }
3297
3298
3299 /* JVM_GetEnclosingMethodInfo */
3300
3301 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
3302 {
3303         classinfo                 *c;
3304         methodinfo                *m;
3305         java_handle_objectarray_t *oa;
3306
3307         TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
3308
3309         c = LLNI_classinfo_unwrap(ofClass);
3310
3311         if ((c == NULL) || class_is_primitive(c))
3312                 return NULL;
3313
3314         m = class_get_enclosingmethod_raw(c);
3315
3316         if (m == NULL)
3317                 return NULL;
3318
3319         oa = builtin_anewarray(3, class_java_lang_Object);
3320
3321         if (oa == NULL)
3322                 return NULL;
3323
3324         array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
3325         array_objectarray_element_set(oa, 1, javastring_new(m->name));
3326         array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
3327
3328         return (jobjectArray) oa;
3329 }
3330
3331
3332 /* JVM_GetThreadStateValues */
3333
3334 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
3335 {
3336         java_handle_intarray_t *ia;
3337
3338         TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
3339                                   env, javaThreadState));
3340
3341         /* If new thread states are added in future JDK and VM versions,
3342            this should check if the JDK version is compatible with thread
3343            states supported by the VM.  Return NULL if not compatible.
3344         
3345            This function must map the VM java_lang_Thread::ThreadStatus
3346            to the Java thread state that the JDK supports. */
3347
3348         switch (javaThreadState) {
3349     case THREAD_STATE_NEW:
3350                 ia = builtin_newarray_int(1);
3351
3352                 if (ia == NULL)
3353                         return NULL;
3354
3355                 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
3356                 break; 
3357
3358     case THREAD_STATE_RUNNABLE:
3359                 ia = builtin_newarray_int(1);
3360
3361                 if (ia == NULL)
3362                         return NULL;
3363
3364                 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
3365                 break; 
3366
3367     case THREAD_STATE_BLOCKED:
3368                 ia = builtin_newarray_int(1);
3369
3370                 if (ia == NULL)
3371                         return NULL;
3372
3373                 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
3374                 break; 
3375
3376     case THREAD_STATE_WAITING:
3377                 ia = builtin_newarray_int(2);
3378
3379                 if (ia == NULL)
3380                         return NULL;
3381
3382                 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
3383                 array_intarray_element_set(ia, 1, THREAD_STATE_PARKED);
3384                 break; 
3385
3386     case THREAD_STATE_TIMED_WAITING:
3387                 ia = builtin_newarray_int(2);
3388
3389                 if (ia == NULL)
3390                         return NULL;
3391
3392                 /* XXX Not sure about that one. */
3393 /*              array_intarray_element_set(ia, 0, SLEEPING); */
3394                 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
3395                 array_intarray_element_set(ia, 1, THREAD_STATE_TIMED_PARKED);
3396                 break; 
3397
3398     case THREAD_STATE_TERMINATED:
3399                 ia = builtin_newarray_int(1);
3400
3401                 if (ia == NULL)
3402                         return NULL;
3403
3404                 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
3405                 break; 
3406
3407     default:
3408                 /* Unknown state - probably incompatible JDK version */
3409                 return NULL;
3410         }
3411
3412         return (jintArray) ia;
3413 }
3414
3415
3416 /* JVM_GetThreadStateNames */
3417
3418 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
3419 {
3420         java_handle_intarray_t    *ia;
3421         java_handle_objectarray_t *oa;
3422         java_object_t             *s;
3423
3424         TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
3425                                   env, javaThreadState, values));
3426
3427         ia = (java_handle_intarray_t *) values;
3428
3429         /* If new thread states are added in future JDK and VM versions,
3430            this should check if the JDK version is compatible with thread
3431            states supported by the VM.  Return NULL if not compatible.
3432         
3433            This function must map the VM java_lang_Thread::ThreadStatus
3434            to the Java thread state that the JDK supports. */
3435
3436         if (values == NULL) {
3437                 exceptions_throw_nullpointerexception();
3438                 return NULL;
3439         }
3440
3441         switch (javaThreadState) {
3442     case THREAD_STATE_NEW:
3443                 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
3444
3445                 oa = builtin_anewarray(1, class_java_lang_String);
3446
3447                 if (oa == NULL)
3448                         return NULL;
3449
3450                 s = javastring_new(utf_new_char("NEW"));
3451
3452                 if (s == NULL)
3453                         return NULL;
3454
3455                 array_objectarray_element_set(oa, 0, s);
3456                 break; 
3457
3458     case THREAD_STATE_RUNNABLE:
3459                 oa = builtin_anewarray(1, class_java_lang_String);
3460
3461                 if (oa == NULL)
3462                         return NULL;
3463
3464                 s = javastring_new(utf_new_char("RUNNABLE"));
3465
3466                 if (s == NULL)
3467                         return NULL;
3468
3469                 array_objectarray_element_set(oa, 0, s);
3470                 break; 
3471
3472     case THREAD_STATE_BLOCKED:
3473                 oa = builtin_anewarray(1, class_java_lang_String);
3474
3475                 if (oa == NULL)
3476                         return NULL;
3477
3478                 s = javastring_new(utf_new_char("BLOCKED"));
3479
3480                 if (s == NULL)
3481                         return NULL;
3482
3483                 array_objectarray_element_set(oa, 0, s);
3484                 break; 
3485
3486     case THREAD_STATE_WAITING:
3487                 oa = builtin_anewarray(2, class_java_lang_String);
3488
3489                 if (oa == NULL)
3490                         return NULL;
3491
3492                 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
3493
3494                 if (s == NULL)
3495                         return NULL;
3496
3497                 array_objectarray_element_set(oa, 0, s);
3498
3499                 s = javastring_new(utf_new_char("WAITING.PARKED"));
3500
3501                 if (s == NULL)
3502                         return NULL;
3503
3504                 array_objectarray_element_set(oa, 1, s);
3505                 break; 
3506
3507     case THREAD_STATE_TIMED_WAITING:
3508                 oa = builtin_anewarray(2, class_java_lang_String);
3509
3510                 if (oa == NULL)
3511                         return NULL;
3512
3513 /*              s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
3514                 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
3515
3516                 if (s == NULL)
3517                         return NULL;
3518
3519                 array_objectarray_element_set(oa, 0, s);
3520
3521                 s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
3522
3523                 if (s == NULL)
3524                         return NULL;
3525
3526                 array_objectarray_element_set(oa, 1, s);
3527                 break; 
3528
3529     case THREAD_STATE_TERMINATED:
3530                 oa = builtin_anewarray(1, class_java_lang_String);
3531
3532                 if (oa == NULL)
3533                         return NULL;
3534
3535                 s = javastring_new(utf_new_char("TERMINATED"));
3536
3537                 if (s == NULL)
3538                         return NULL;
3539
3540                 array_objectarray_element_set(oa, 0, s);
3541                 break; 
3542
3543         default:
3544                 /* Unknown state - probably incompatible JDK version */
3545                 return NULL;
3546         }
3547
3548         return (jobjectArray) oa;
3549 }
3550
3551
3552 /* JVM_GetVersionInfo */
3553
3554 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3555 {
3556         log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3557 }
3558
3559
3560 /* OS: JVM_RegisterSignal */
3561
3562 void *JVM_RegisterSignal(jint sig, void *handler)
3563 {
3564         functionptr newHandler;
3565
3566         TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
3567
3568         if (handler == (void *) 2)
3569                 newHandler = (functionptr) signal_thread_handler;
3570         else
3571                 newHandler = (functionptr) (uintptr_t) handler;
3572
3573         switch (sig) {
3574     case SIGILL:
3575     case SIGFPE:
3576     case SIGUSR1:
3577     case SIGSEGV:
3578                 /* These signals are already used by the VM. */
3579                 return (void *) -1;
3580
3581     case SIGQUIT:
3582                 /* This signal is used by the VM to dump thread stacks unless
3583                    ReduceSignalUsage is set, in which case the user is allowed
3584                    to set his own _native_ handler for this signal; thus, in
3585                    either case, we do not allow JVM_RegisterSignal to change
3586                    the handler. */
3587                 return (void *) -1;
3588
3589         case SIGHUP:
3590         case SIGINT:
3591         case SIGTERM:
3592                 break;
3593         }
3594
3595         signal_register_signal(sig, newHandler, SA_RESTART | SA_SIGINFO);
3596
3597         /* XXX Should return old handler. */
3598
3599         return (void *) 2;
3600 }
3601
3602
3603 /* OS: JVM_RaiseSignal */
3604
3605 jboolean JVM_RaiseSignal(jint sig)
3606 {
3607         log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3608
3609         return false;
3610 }
3611
3612
3613 /* OS: JVM_FindSignal */
3614
3615 jint JVM_FindSignal(const char *name)
3616 {
3617         TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
3618
3619 #if defined(__LINUX__)
3620         if (strcmp(name, "HUP") == 0)
3621                 return SIGHUP;
3622
3623         if (strcmp(name, "INT") == 0)
3624                 return SIGINT;
3625
3626         if (strcmp(name, "TERM") == 0)
3627                 return SIGTERM;
3628 #elif defined(__SOLARIS__)
3629         int signum;
3630
3631         if (os::str2sig(name, &signum) == -1)
3632                 return -1;
3633
3634         return signum;
3635 #else
3636 # error Not implemented for this OS.
3637 #endif
3638
3639         return -1;
3640 }
3641
3642 } // extern "C"
3643
3644
3645 /*
3646  * These are local overrides for various environment variables in Emacs.
3647  * Please do not remove this and leave it at the end of the file, where
3648  * Emacs will automagically detect them.
3649  * ---------------------------------------------------------------------
3650  * Local variables:
3651  * mode: c++
3652  * indent-tabs-mode: t
3653  * c-basic-offset: 4
3654  * tab-width: 4
3655  * End:
3656  * vim:noexpandtab:sw=4:ts=4:
3657  */