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