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