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