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