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