* Half way to C++ wrapper classes for OpenJDK. More to come.
[cacao.git] / src / native / vm / openjdk / jvm.cpp
1 /* src/native/vm/openjdk/jvm.cpp - HotSpot VM interface functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <errno.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <unistd.h>
34
35 #if defined(HAVE_SYS_IOCTL_H)
36 #define BSD_COMP /* Get FIONREAD on Solaris2 */
37 #include <sys/ioctl.h>
38 #endif
39
40 #include <sys/socket.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
43
44 #include "vm/types.h"
45
46 #include "mm/memory.h"
47
48 #include "native/jni.h"
49 #include "native/llni.h"
50 #include "native/native.h"
51
52 #include "native/vm/reflection.hpp"
53
54 #include "native/vm/openjdk/hpi.h"
55
56 #include "threads/lock-common.h"
57 #include "threads/thread.hpp"
58
59 #include "toolbox/logging.h"
60 #include "toolbox/list.h"
61
62 #include "vm/array.h"
63
64 #if defined(ENABLE_ASSERTION)
65 #include "vm/assertion.h"
66 #endif
67
68 #include "vm/builtin.h"
69 #include "vm/exceptions.hpp"
70 #include "vm/global.h"
71 #include "vm/initialize.h"
72 #include "vm/package.hpp"
73 #include "vm/primitive.hpp"
74 #include "vm/properties.h"
75 #include "vm/resolve.h"
76 #include "vm/signallocal.h"
77 #include "vm/string.hpp"
78 #include "vm/vm.hpp"
79
80 #include "vm/jit/stacktrace.hpp"
81
82 #include "vmcore/classcache.h"
83 #include "vmcore/globals.hpp"
84 #include "vmcore/javaobjects.hpp"
85 #include "vmcore/options.h"
86 #include "vmcore/os.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         properties_add("sun.nio.MaxDirectMemorySize", buf);
290
291         /* Add all properties. */
292
293         properties_system_add_all(h);
294
295         return properties;
296 }
297
298
299 /* JVM_Exit */
300
301 void JVM_Exit(jint code)
302 {
303         log_println("JVM_Exit: IMPLEMENT ME!");
304 }
305
306
307 /* JVM_Halt */
308
309 void JVM_Halt(jint code)
310 {
311         TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
312
313 /*      vm_exit(code); */
314         vm_shutdown(code);
315 }
316
317
318 /* JVM_OnExit(void (*func)) */
319
320 void JVM_OnExit(void (*func)(void))
321 {
322         log_println("JVM_OnExit(void (*func): IMPLEMENT ME!");
323 }
324
325
326 /* JVM_GC */
327
328 void JVM_GC(void)
329 {
330         TRACEJVMCALLS(("JVM_GC()"));
331
332         gc_call();
333 }
334
335
336 /* JVM_MaxObjectInspectionAge */
337
338 jlong JVM_MaxObjectInspectionAge(void)
339 {
340         log_println("JVM_MaxObjectInspectionAge: IMPLEMENT ME!");
341
342         return 0;
343 }
344
345
346 /* JVM_TraceInstructions */
347
348 void JVM_TraceInstructions(jboolean on)
349 {
350         log_println("JVM_TraceInstructions: IMPLEMENT ME!");
351 }
352
353
354 /* JVM_TraceMethodCalls */
355
356 void JVM_TraceMethodCalls(jboolean on)
357 {
358         log_println("JVM_TraceMethodCalls: IMPLEMENT ME!");
359 }
360
361
362 /* JVM_TotalMemory */
363
364 jlong JVM_TotalMemory(void)
365 {
366         TRACEJVMCALLS(("JVM_TotalMemory()"));
367
368         return gc_get_heap_size();
369 }
370
371
372 /* JVM_FreeMemory */
373
374 jlong JVM_FreeMemory(void)
375 {
376         TRACEJVMCALLS(("JVM_FreeMemory()"));
377
378         return gc_get_free_bytes();
379 }
380
381
382 /* JVM_MaxMemory */
383
384 jlong JVM_MaxMemory(void)
385 {
386         TRACEJVMCALLS(("JVM_MaxMemory()"));
387
388         return gc_get_max_heap_size();
389 }
390
391
392 /* JVM_ActiveProcessorCount */
393
394 jint JVM_ActiveProcessorCount(void)
395 {
396         TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
397
398         return os::processors_online();
399 }
400
401
402 /* JVM_FillInStackTrace */
403
404 void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
405 {
406         TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
407
408         java_handle_bytearray_t* ba = stacktrace_get_current();
409
410         if (ba == NULL)
411                 return;
412
413         java_lang_Throwable jlt(receiver, ba);
414 }
415
416
417 /* JVM_PrintStackTrace */
418
419 void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
420 {
421         log_println("JVM_PrintStackTrace: IMPLEMENT ME!");
422 }
423
424
425 /* JVM_GetStackTraceDepth */
426
427 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
428 {
429         TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
430
431         java_lang_Throwable jlt(throwable);
432
433         if (jlt.is_null()) {
434                 exceptions_throw_nullpointerexception();
435                 return 0;
436         }
437
438         java_handle_bytearray_t* ba = jlt.get_backtrace();
439
440         if (ba == NULL)
441                 return 0;
442
443         // We need a critical section here as the stacktrace structure is
444         // mapped onto a Java byte-array.
445
446         LLNI_CRITICAL_START;
447
448         stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
449
450         int32_t depth = st->length;
451
452         LLNI_CRITICAL_END;
453
454         return depth;
455 }
456
457
458 /* JVM_GetStackTraceElement */
459
460 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
461 {
462         TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
463
464         java_lang_Throwable jlt(throwable);
465         java_handle_bytearray_t* ba = jlt.get_backtrace();
466
467         // We need a critical section here as the stacktrace structure is
468         // mapped onto a Java byte-array.
469         LLNI_CRITICAL_START;
470
471         stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
472
473         if ((index < 0) || (index >= st->length)) {
474                 /* XXX This should be an IndexOutOfBoundsException (check this
475                    again). */
476                 exceptions_throw_arrayindexoutofboundsexception();
477                 return NULL;
478         }
479
480         // Get the stacktrace entry.
481         stacktrace_entry_t* ste = &(st->entries[index]);
482
483         // Get the codeinfo, methodinfo and classinfo.
484         codeinfo*   code = ste->code;
485         methodinfo* m    = code->m;
486         classinfo*  c    = m->clazz;
487
488         // Get filename.
489         java_handle_t* filename;
490
491         if (!(m->flags & ACC_NATIVE)) {
492                 if (c->sourcefile != NULL)
493                         filename = javastring_new(c->sourcefile);
494                 else
495                         filename = NULL;
496         }
497         else
498                 filename = NULL;
499
500         // Get line number.
501         int32_t linenumber;
502
503         if (m->flags & ACC_NATIVE) {
504                 linenumber = -2;
505         }
506         else {
507                 /* FIXME The linenumbertable_linenumber_for_pc could change
508                    the methodinfo pointer when hitting an inlined method. */
509
510                 linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
511                 linenumber = (linenumber == 0) ? -1 : linenumber;
512         }
513
514         LLNI_CRITICAL_END;
515
516         // Get declaring class name.
517         java_handle_t* declaringclass = class_get_classname(c);
518
519         // Allocate a new StackTraceElement object.
520         java_lang_StackTraceElement jlste(declaringclass, javastring_new(m->name), filename, linenumber);
521
522         if (jlste.is_null())
523                 return NULL;
524
525         return (jobject) jlste.get_handle();
526 }
527
528
529 /* JVM_IHashCode */
530
531 jint JVM_IHashCode(JNIEnv* env, jobject handle)
532 {
533         TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
534
535         return (jint) ((ptrint) handle);
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() == 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         classinfo                 *c;
1267         java_handle_objectarray_t *oa;
1268
1269         TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1270
1271         c = LLNI_classinfo_unwrap(ofClass);
1272
1273         oa = class_get_declaredmethods(c, publicOnly);
1274
1275         return (jobjectArray) oa;
1276 }
1277
1278
1279 /* JVM_GetClassDeclaredConstructors */
1280
1281 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
1282 {
1283         classinfo                 *c;
1284         java_handle_objectarray_t *oa;
1285
1286         TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
1287
1288         c = LLNI_classinfo_unwrap(ofClass);
1289
1290         oa = class_get_declaredconstructors(c, publicOnly);
1291
1292         return (jobjectArray) oa;
1293 }
1294
1295
1296 /* JVM_GetClassAccessFlags */
1297
1298 jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
1299 {
1300         classinfo *c;
1301
1302         TRACEJVMCALLS(("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls));
1303
1304         c = LLNI_classinfo_unwrap(cls);
1305
1306         /* Primitive type classes have the correct access flags. */
1307
1308         return c->flags & ACC_CLASS_REFLECT_MASK;
1309 }
1310
1311
1312 /* JVM_GetClassConstantPool */
1313
1314 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
1315 {
1316 #if defined(ENABLE_ANNOTATIONS)
1317         TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
1318
1319         java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
1320         sun_reflect_ConstantPool cp(h, cls);
1321         
1322         if (cp.is_null()) {
1323                 return NULL;
1324         }
1325         
1326         return (jobject) cp.get_handle();
1327 #else
1328         log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
1329         return NULL;
1330 #endif
1331 }
1332
1333
1334 /* JVM_ConstantPoolGetSize */
1335
1336 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
1337 {
1338         classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
1339
1340         TRACEJVMCALLS(("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool));
1341
1342         c = LLNI_classinfo_unwrap(jcpool);
1343
1344         return c->cpcount;
1345 }
1346
1347
1348 /* JVM_ConstantPoolGetClassAt */
1349
1350 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1351 {
1352         constant_classref *ref;    /* classref to the class at constant pool index 'index' */
1353         classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
1354         classinfo         *result; /* classinfo of the class at constant pool index 'index' */
1355
1356         TRACEJVMCALLS(("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index));
1357
1358         c = LLNI_classinfo_unwrap(jcpool);
1359
1360         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1361
1362         if (ref == NULL) {
1363                 exceptions_throw_illegalargumentexception();
1364                 return NULL;
1365         }
1366
1367         result = resolve_classref_eager(ref);
1368
1369         return (jclass) LLNI_classinfo_wrap(result);
1370 }
1371
1372
1373 /* JVM_ConstantPoolGetClassAtIfLoaded */
1374
1375 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1376 {
1377         constant_classref *ref;    /* classref to the class at constant pool index 'index' */
1378         classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
1379         classinfo         *result; /* classinfo of the class at constant pool index 'index' */
1380
1381         TRACEJVMCALLS(("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index));
1382
1383         c = LLNI_classinfo_unwrap(jcpool);
1384
1385         ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
1386
1387         if (ref == NULL) {
1388                 exceptions_throw_illegalargumentexception();
1389                 return NULL;
1390         }
1391         
1392         if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result)) {
1393                 return NULL;
1394         }
1395
1396         if ((result == NULL) || !(result->state & CLASS_LOADED)) {
1397                 return NULL;
1398         }
1399         
1400         return (jclass) LLNI_classinfo_wrap(result);
1401 }
1402
1403
1404 /* JVM_ConstantPoolGetMethodAt */
1405
1406 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1407 {
1408         constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
1409         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1410         
1411         TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index));
1412         
1413         cls = LLNI_classinfo_unwrap(jcpool);
1414         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
1415         
1416         if (ref == NULL) {
1417                 exceptions_throw_illegalargumentexception();
1418                 return NULL;
1419         }
1420
1421         /* XXX: is that right? or do I have to use resolve_method_*? */
1422         return (jobject)reflect_method_new(ref->p.method);
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         return (jobject)reflect_method_new(ref->p.method);
1453 }
1454
1455
1456 /* JVM_ConstantPoolGetFieldAt */
1457
1458 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1459 {
1460         constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1461         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1462         
1463         TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index));
1464
1465         cls = LLNI_classinfo_unwrap(jcpool);
1466         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1467
1468         if (ref == NULL) {
1469                 exceptions_throw_illegalargumentexception();
1470                 return NULL;
1471         }
1472
1473         return (jobject)reflect_field_new(ref->p.field);
1474 }
1475
1476
1477 /* JVM_ConstantPoolGetFieldAtIfLoaded */
1478
1479 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1480 {
1481         constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
1482         classinfo *c;         /* resolved declaring class for the field */
1483         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1484
1485         TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
1486
1487         cls = LLNI_classinfo_unwrap(jcpool);
1488         ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
1489
1490         if (ref == NULL) {
1491                 exceptions_throw_illegalargumentexception();
1492                 return NULL;
1493         }
1494
1495         if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
1496                 return NULL;
1497         }
1498
1499         if (c == NULL || !(c->state & CLASS_LOADED)) {
1500                 return NULL;
1501         }
1502
1503         return (jobject)reflect_field_new(ref->p.field);
1504 }
1505
1506
1507 /* JVM_ConstantPoolGetMemberRefInfoAt */
1508
1509 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1510 {
1511         log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
1512
1513         /* TODO: implement. (this is yet unused be OpenJDK but, so very low priority) */
1514
1515         return NULL;
1516 }
1517
1518
1519 /* JVM_ConstantPoolGetIntAt */
1520
1521 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1522 {
1523         constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
1524         classinfo *cls;        /* classinfo of the class for which 'this' is the constant pool */
1525
1526         TRACEJVMCALLS(("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index));
1527
1528         cls = LLNI_classinfo_unwrap(jcpool);
1529         ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
1530
1531         if (ref == NULL) {
1532                 exceptions_throw_illegalargumentexception();
1533                 return 0;
1534         }
1535
1536         return ref->value;
1537 }
1538
1539
1540 /* JVM_ConstantPoolGetLongAt */
1541
1542 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1543 {
1544         constant_long *ref; /* reference to the long value in constant pool at index 'index' */
1545         classinfo *cls;     /* classinfo of the class for which 'this' is the constant pool */
1546
1547         TRACEJVMCALLS(("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index));
1548
1549         cls = LLNI_classinfo_unwrap(jcpool);
1550         ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
1551
1552         if (ref == NULL) {
1553                 exceptions_throw_illegalargumentexception();
1554                 return 0;
1555         }
1556
1557         return ref->value;
1558 }
1559
1560
1561 /* JVM_ConstantPoolGetFloatAt */
1562
1563 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1564 {
1565         constant_float *ref; /* reference to the float value in constant pool at index 'index' */
1566         classinfo *cls;      /* classinfo of the class for which 'this' is the constant pool */
1567
1568         TRACEJVMCALLS(("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index));
1569
1570         cls = LLNI_classinfo_unwrap(jcpool);
1571         ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
1572
1573         if (ref == NULL) {
1574                 exceptions_throw_illegalargumentexception();
1575                 return 0;
1576         }
1577
1578         return ref->value;
1579 }
1580
1581
1582 /* JVM_ConstantPoolGetDoubleAt */
1583
1584 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1585 {
1586         constant_double *ref; /* reference to the double value in constant pool at index 'index' */
1587         classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
1588
1589         TRACEJVMCALLS(("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index));
1590
1591         cls = LLNI_classinfo_unwrap(jcpool);
1592         ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
1593
1594         if (ref == NULL) {
1595                 exceptions_throw_illegalargumentexception();
1596                 return 0;
1597         }
1598
1599         return ref->value;
1600 }
1601
1602
1603 /* JVM_ConstantPoolGetStringAt */
1604
1605 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1606 {
1607         utf *ref;       /* utf object for the string in constant pool at index 'index' */
1608         classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1609
1610         TRACEJVMCALLS(("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index));
1611         
1612         cls = LLNI_classinfo_unwrap(jcpool);
1613         ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
1614
1615         if (ref == NULL) {
1616                 exceptions_throw_illegalargumentexception();
1617                 return NULL;
1618         }
1619
1620         /* XXX: I hope literalstring_new is the right Function. */
1621         return (jstring)literalstring_new(ref);
1622 }
1623
1624
1625 /* JVM_ConstantPoolGetUTF8At */
1626
1627 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
1628 {
1629         utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
1630         classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
1631
1632         TRACEJVMCALLS(("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index));
1633
1634         cls = LLNI_classinfo_unwrap(jcpool);
1635         ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
1636
1637         if (ref == NULL) {
1638                 exceptions_throw_illegalargumentexception();
1639                 return NULL;
1640         }
1641
1642         /* XXX: I hope literalstring_new is the right Function. */
1643         return (jstring)literalstring_new(ref);
1644 }
1645
1646
1647 /* JVM_DesiredAssertionStatus */
1648
1649 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
1650 {
1651 #if defined(ENABLE_ASSERTION)
1652         assertion_name_t  *item;
1653         classinfo         *c;
1654         jboolean           status;
1655         utf               *name;
1656
1657         TRACEJVMCALLS(("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls));
1658
1659         c = LLNI_classinfo_unwrap(cls);
1660
1661         if (c->classloader == NULL) {
1662                 status = (jboolean)assertion_system_enabled;
1663         }
1664         else {
1665                 status = (jboolean)assertion_user_enabled;
1666         }
1667
1668         if (list_assertion_names != NULL) {
1669                 item = (assertion_name_t *)list_first(list_assertion_names);
1670                 while (item != NULL) {
1671                         name = utf_new_char(item->name);
1672                         if (name == c->packagename) {
1673                                 status = (jboolean)item->enabled;
1674                         }
1675                         else if (name == c->name) {
1676                                 status = (jboolean)item->enabled;
1677                         }
1678
1679                         item = (assertion_name_t *)list_next(list_assertion_names, item);
1680                 }
1681         }
1682
1683         return status;
1684 #else
1685         return (jboolean)false;
1686 #endif
1687 }
1688
1689
1690 /* JVM_AssertionStatusDirectives */
1691
1692 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
1693 {
1694         classinfo                             *c;
1695         java_lang_AssertionStatusDirectives   *o;
1696         java_handle_objectarray_t             *classes;
1697         java_handle_objectarray_t             *packages;
1698         java_booleanarray_t                   *classEnabled;
1699         java_booleanarray_t                   *packageEnabled;
1700 #if defined(ENABLE_ASSERTION)
1701         assertion_name_t                      *item;
1702         java_handle_t                         *js;
1703         s4                                     i, j;
1704 #endif
1705
1706         TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
1707
1708         c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
1709
1710         if (c == NULL)
1711                 return NULL;
1712
1713         o = (java_lang_AssertionStatusDirectives *) builtin_new(c);
1714
1715         if (o == NULL)
1716                 return NULL;
1717
1718 #if defined(ENABLE_ASSERTION)
1719         classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
1720 #else
1721         classes = builtin_anewarray(0, class_java_lang_Object);
1722 #endif
1723         if (classes == NULL)
1724                 return NULL;
1725
1726 #if defined(ENABLE_ASSERTION)
1727         packages = builtin_anewarray(assertion_package_count, class_java_lang_Object);
1728 #else
1729         packages = builtin_anewarray(0, class_java_lang_Object);
1730 #endif
1731         if (packages == NULL)
1732                 return NULL;
1733         
1734 #if defined(ENABLE_ASSERTION)
1735         classEnabled = builtin_newarray_boolean(assertion_class_count);
1736 #else
1737         classEnabled = builtin_newarray_boolean(0);
1738 #endif
1739         if (classEnabled == NULL)
1740                 return NULL;
1741
1742 #if defined(ENABLE_ASSERTION)
1743         packageEnabled = builtin_newarray_boolean(assertion_package_count);
1744 #else
1745         packageEnabled = builtin_newarray_boolean(0);
1746 #endif
1747         if (packageEnabled == NULL)
1748                 return NULL;
1749
1750 #if defined(ENABLE_ASSERTION)
1751         /* initialize arrays */
1752
1753         if (list_assertion_names != NULL) {
1754                 i = 0;
1755                 j = 0;
1756                 
1757                 item = (assertion_name_t *)list_first(list_assertion_names);
1758                 while (item != NULL) {
1759                         js = javastring_new_from_ascii(item->name);
1760                         if (js == NULL) {
1761                                 return NULL;
1762                         }
1763
1764                         if (item->package == false) {
1765                                 classes->data[i] = js;
1766                                 classEnabled->data[i] = (jboolean) item->enabled;
1767                                 i += 1;
1768                         }
1769                         else {
1770                                 packages->data[j] = js;
1771                                 packageEnabled->data[j] = (jboolean) item->enabled;
1772                                 j += 1;
1773                         }
1774
1775                         item = (assertion_name_t *)list_next(list_assertion_names, item);
1776                 }
1777         }
1778 #endif
1779
1780         /* set instance fields */
1781
1782         o->classes  = classes;
1783         o->packages = packages;
1784         o->classEnabled = classEnabled;
1785         o->packageEnabled = packageEnabled;
1786
1787         return (jobject) o;
1788 }
1789
1790
1791 /* JVM_GetClassNameUTF */
1792
1793 const char *JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
1794 {
1795         log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
1796
1797         return NULL;
1798 }
1799
1800
1801 /* JVM_GetClassCPTypes */
1802
1803 void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
1804 {
1805         log_println("JVM_GetClassCPTypes: IMPLEMENT ME!");
1806 }
1807
1808
1809 /* JVM_GetClassCPEntriesCount */
1810
1811 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
1812 {
1813         log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
1814
1815         return 0;
1816 }
1817
1818
1819 /* JVM_GetClassFieldsCount */
1820
1821 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
1822 {
1823         log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
1824
1825         return 0;
1826 }
1827
1828
1829 /* JVM_GetClassMethodsCount */
1830
1831 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
1832 {
1833         log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
1834
1835         return 0;
1836 }
1837
1838
1839 /* JVM_GetMethodIxExceptionIndexes */
1840
1841 void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)
1842 {
1843         log_println("JVM_GetMethodIxExceptionIndexes: IMPLEMENT ME!");
1844 }
1845
1846
1847 /* JVM_GetMethodIxExceptionsCount */
1848
1849 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
1850 {
1851         log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
1852
1853         return 0;
1854 }
1855
1856
1857 /* JVM_GetMethodIxByteCode */
1858
1859 void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)
1860 {
1861         log_println("JVM_GetMethodIxByteCode: IMPLEMENT ME!");
1862 }
1863
1864
1865 /* JVM_GetMethodIxByteCodeLength */
1866
1867 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
1868 {
1869         log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
1870
1871         return 0;
1872 }
1873
1874
1875 /* JVM_GetMethodIxExceptionTableEntry */
1876
1877 void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)
1878 {
1879         log_println("JVM_GetMethodIxExceptionTableEntry: IMPLEMENT ME!");
1880 }
1881
1882
1883 /* JVM_GetMethodIxExceptionTableLength */
1884
1885 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
1886 {
1887         log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
1888
1889         return 0;
1890 }
1891
1892
1893 /* JVM_GetMethodIxModifiers */
1894
1895 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
1896 {
1897         log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
1898
1899         return 0;
1900 }
1901
1902
1903 /* JVM_GetFieldIxModifiers */
1904
1905 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
1906 {
1907         log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
1908
1909         return 0;
1910 }
1911
1912
1913 /* JVM_GetMethodIxLocalsCount */
1914
1915 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
1916 {
1917         log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
1918
1919         return 0;
1920 }
1921
1922
1923 /* JVM_GetMethodIxArgsSize */
1924
1925 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
1926 {
1927         log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
1928
1929         return 0;
1930 }
1931
1932
1933 /* JVM_GetMethodIxMaxStack */
1934
1935 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
1936 {
1937         log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
1938
1939         return 0;
1940 }
1941
1942
1943 /* JVM_IsConstructorIx */
1944
1945 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
1946 {
1947         log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
1948
1949         return 0;
1950 }
1951
1952
1953 /* JVM_GetMethodIxNameUTF */
1954
1955 const char *JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
1956 {
1957         log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
1958
1959         return NULL;
1960 }
1961
1962
1963 /* JVM_GetMethodIxSignatureUTF */
1964
1965 const char *JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
1966 {
1967         log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
1968
1969         return NULL;
1970 }
1971
1972
1973 /* JVM_GetCPFieldNameUTF */
1974
1975 const char *JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1976 {
1977         log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
1978
1979         return NULL;
1980 }
1981
1982
1983 /* JVM_GetCPMethodNameUTF */
1984
1985 const char *JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
1986 {
1987         log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
1988
1989         return NULL;
1990 }
1991
1992
1993 /* JVM_GetCPMethodSignatureUTF */
1994
1995 const char *JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
1996 {
1997         log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
1998
1999         return NULL;
2000 }
2001
2002
2003 /* JVM_GetCPFieldSignatureUTF */
2004
2005 const char *JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
2006 {
2007         log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
2008
2009         return NULL;
2010 }
2011
2012
2013 /* JVM_GetCPClassNameUTF */
2014
2015 const char *JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2016 {
2017         log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
2018
2019         return NULL;
2020 }
2021
2022
2023 /* JVM_GetCPFieldClassNameUTF */
2024
2025 const char *JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2026 {
2027         log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
2028
2029         return NULL;
2030 }
2031
2032
2033 /* JVM_GetCPMethodClassNameUTF */
2034
2035 const char *JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
2036 {
2037         log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
2038
2039         return NULL;
2040 }
2041
2042
2043 /* JVM_GetCPFieldModifiers */
2044
2045 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
2046 {
2047         log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
2048
2049         return 0;
2050 }
2051
2052
2053 /* JVM_GetCPMethodModifiers */
2054
2055 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
2056 {
2057         log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
2058
2059         return 0;
2060 }
2061
2062
2063 /* JVM_ReleaseUTF */
2064
2065 void JVM_ReleaseUTF(const char *utf)
2066 {
2067         log_println("JVM_ReleaseUTF: IMPLEMENT ME!");
2068 }
2069
2070
2071 /* JVM_IsSameClassPackage */
2072
2073 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
2074 {
2075         log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
2076
2077         return 0;
2078 }
2079
2080
2081 /* JVM_Open */
2082
2083 /* Taken from: hotspot/src/share/vm/prims/jvm.h */
2084
2085 /*
2086  * JVM I/O error codes
2087  */
2088 #define JVM_EEXIST       -100
2089
2090 jint JVM_Open(const char *fname, jint flags, jint mode)
2091 {
2092         int result;
2093
2094         TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
2095
2096         result = hpi_file->Open(fname, flags, mode);
2097
2098         if (result >= 0) {
2099                 return result;
2100         }
2101         else {
2102                 switch (errno) {
2103                 case EEXIST:
2104                         return JVM_EEXIST;
2105                 default:
2106                         return -1;
2107                 }
2108         }
2109 }
2110
2111
2112 /* JVM_Close */
2113
2114 jint JVM_Close(jint fd)
2115 {
2116         TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
2117
2118         return hpi_file->Close(fd);
2119 }
2120
2121
2122 /* JVM_Read */
2123
2124 jint JVM_Read(jint fd, char *buf, jint nbytes)
2125 {
2126         TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
2127
2128         return (jint) hpi_file->Read(fd, buf, nbytes);
2129 }
2130
2131
2132 /* JVM_Write */
2133
2134 jint JVM_Write(jint fd, char *buf, jint nbytes)
2135 {
2136         TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
2137
2138         return (jint) hpi_file->Write(fd, buf, nbytes);
2139 }
2140
2141
2142 /* JVM_Available */
2143
2144 jint JVM_Available(jint fd, jlong *pbytes)
2145 {
2146         TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
2147
2148         return hpi_file->Available(fd, pbytes);
2149 }
2150
2151
2152 /* JVM_Lseek */
2153
2154 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
2155 {
2156         TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
2157
2158         return hpi_file->Seek(fd, (off_t) offset, whence);
2159 }
2160
2161
2162 /* JVM_SetLength */
2163
2164 jint JVM_SetLength(jint fd, jlong length)
2165 {
2166         TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
2167
2168         return hpi_file->SetLength(fd, length);
2169 }
2170
2171
2172 /* JVM_Sync */
2173
2174 jint JVM_Sync(jint fd)
2175 {
2176         TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
2177
2178         return hpi_file->Sync(fd);
2179 }
2180
2181
2182 /* JVM_StartThread */
2183
2184 void JVM_StartThread(JNIEnv* env, jobject jthread)
2185 {
2186         TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
2187
2188         threads_thread_start((java_handle_t *) jthread);
2189 }
2190
2191
2192 /* JVM_StopThread */
2193
2194 void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
2195 {
2196         log_println("JVM_StopThread: Deprecated.  Not implemented.");
2197 }
2198
2199
2200 /* JVM_IsThreadAlive */
2201
2202 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
2203 {
2204         java_handle_t *h;
2205         threadobject  *t;
2206         bool           result;
2207
2208         TRACEJVMCALLS(("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread));
2209
2210         h = (java_handle_t *) jthread;
2211         t = thread_get_thread(h);
2212
2213         /* The threadobject is null when a thread is created in Java. The
2214            priority is set later during startup. */
2215
2216         if (t == NULL)
2217                 return 0;
2218
2219         result = threads_thread_is_alive(t);
2220
2221         return result;
2222 }
2223
2224
2225 /* JVM_SuspendThread */
2226
2227 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
2228 {
2229         log_println("JVM_SuspendThread: Deprecated.  Not implemented.");
2230 }
2231
2232
2233 /* JVM_ResumeThread */
2234
2235 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
2236 {
2237         log_println("JVM_ResumeThread: Deprecated.  Not implemented.");
2238 }
2239
2240
2241 /* JVM_SetThreadPriority */
2242
2243 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
2244 {
2245         java_handle_t *h;
2246         threadobject  *t;
2247
2248         TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
2249
2250         h = (java_handle_t *) jthread;
2251         t = thread_get_thread(h);
2252
2253         /* The threadobject is null when a thread is created in Java. The
2254            priority is set later during startup. */
2255
2256         if (t == NULL)
2257                 return;
2258
2259         threads_set_thread_priority(t->tid, prio);
2260 }
2261
2262
2263 /* JVM_Yield */
2264
2265 void JVM_Yield(JNIEnv *env, jclass threadClass)
2266 {
2267         TRACEJVMCALLS(("JVM_Yield(env=%p, threadClass=%p)", env, threadClass));
2268
2269         threads_yield();
2270 }
2271
2272
2273 /* JVM_Sleep */
2274
2275 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
2276 {
2277         TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
2278
2279         threads_sleep(millis, 0);
2280 }
2281
2282
2283 /* JVM_CurrentThread */
2284
2285 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
2286 {
2287         java_object_t *o;
2288
2289         TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
2290
2291         o = thread_get_current_object();
2292
2293         return (jobject) o;
2294 }
2295
2296
2297 /* JVM_CountStackFrames */
2298
2299 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
2300 {
2301         log_println("JVM_CountStackFrames: Deprecated.  Not implemented.");
2302
2303         return 0;
2304 }
2305
2306
2307 /* JVM_Interrupt */
2308
2309 void JVM_Interrupt(JNIEnv* env, jobject jthread)
2310 {
2311         java_handle_t *h;
2312         threadobject  *t;
2313
2314         TRACEJVMCALLS(("JVM_Interrupt(env=%p, jthread=%p)", env, jthread));
2315
2316         h = (java_handle_t *) jthread;
2317         t = thread_get_thread(h);
2318
2319         if (t == NULL)
2320                 return;
2321
2322         threads_thread_interrupt(t);
2323 }
2324
2325
2326 /* JVM_IsInterrupted */
2327
2328 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
2329 {
2330         java_handle_t *h;
2331         threadobject  *t;
2332         jboolean       interrupted;
2333
2334         TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
2335
2336         h = (java_handle_t *) jthread;
2337         t = thread_get_thread(h);
2338
2339         interrupted = thread_is_interrupted(t);
2340
2341         if (interrupted && clear_interrupted)
2342                 thread_set_interrupted(t, false);
2343
2344         return interrupted;
2345 }
2346
2347
2348 /* JVM_HoldsLock */
2349
2350 jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
2351 {
2352         java_handle_t *h;
2353         bool           result;
2354
2355         TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
2356
2357         h = (java_handle_t *) obj;
2358
2359         if (h == NULL) {
2360                 exceptions_throw_nullpointerexception();
2361                 return JNI_FALSE;
2362         }
2363
2364         result = lock_is_held_by_current_thread(h);
2365
2366         return result;
2367 }
2368
2369
2370 /* JVM_DumpAllStacks */
2371
2372 void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
2373 {
2374         log_println("JVM_DumpAllStacks: IMPLEMENT ME!");
2375 }
2376
2377
2378 /* JVM_CurrentLoadedClass */
2379
2380 jclass JVM_CurrentLoadedClass(JNIEnv *env)
2381 {
2382         log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
2383
2384         return NULL;
2385 }
2386
2387
2388 /* JVM_CurrentClassLoader */
2389
2390 jobject JVM_CurrentClassLoader(JNIEnv *env)
2391 {
2392     /* XXX if a method in a class in a trusted loader is in a
2393            doPrivileged, return NULL */
2394
2395         log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
2396
2397         return NULL;
2398 }
2399
2400
2401 /* JVM_GetClassContext */
2402
2403 jobjectArray JVM_GetClassContext(JNIEnv *env)
2404 {
2405         TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
2406
2407         return (jobjectArray) stacktrace_getClassContext();
2408 }
2409
2410
2411 /* JVM_ClassDepth */
2412
2413 jint JVM_ClassDepth(JNIEnv *env, jstring name)
2414 {
2415         log_println("JVM_ClassDepth: IMPLEMENT ME!");
2416
2417         return 0;
2418 }
2419
2420
2421 /* JVM_ClassLoaderDepth */
2422
2423 jint JVM_ClassLoaderDepth(JNIEnv *env)
2424 {
2425         log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
2426
2427         return 0;
2428 }
2429
2430
2431 /* JVM_GetSystemPackage */
2432
2433 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
2434 {
2435         java_handle_t *s;
2436         utf *u;
2437         utf *result;
2438
2439         TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
2440
2441 /*      s = Package::find(name); */
2442         u = javastring_toutf((java_handle_t *) name, false);
2443
2444         result = Package::find(u);
2445
2446         if (result != NULL)
2447                 s = javastring_new(result);
2448         else
2449                 s = NULL;
2450
2451         return (jstring) s;
2452 }
2453
2454
2455 /* JVM_GetSystemPackages */
2456
2457 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
2458 {
2459         log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
2460
2461         return NULL;
2462 }
2463
2464
2465 /* JVM_AllocateNewObject */
2466
2467 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
2468 {
2469         log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
2470
2471         return NULL;
2472 }
2473
2474
2475 /* JVM_AllocateNewArray */
2476
2477 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
2478 {
2479         log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
2480
2481         return NULL;
2482 }
2483
2484
2485 /* JVM_LatestUserDefinedLoader */
2486
2487 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
2488 {
2489         classloader_t *cl;
2490
2491         TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
2492
2493         cl = stacktrace_first_nonnull_classloader();
2494
2495         return (jobject) cl;
2496 }
2497
2498
2499 /* JVM_LoadClass0 */
2500
2501 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
2502 {
2503         log_println("JVM_LoadClass0: IMPLEMENT ME!");
2504
2505         return NULL;
2506 }
2507
2508
2509 /* JVM_GetArrayLength */
2510
2511 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
2512 {
2513         java_handle_t *a;
2514
2515         TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
2516
2517         a = (java_handle_t *) arr;
2518
2519         return array_length_get(a);
2520 }
2521
2522
2523 /* JVM_GetArrayElement */
2524
2525 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
2526 {
2527         java_handle_t *a;
2528         java_handle_t *o;
2529
2530         TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
2531
2532         a = (java_handle_t *) arr;
2533
2534 /*      if (!class_is_array(a->objheader.vftbl->class)) { */
2535 /*              exceptions_throw_illegalargumentexception(); */
2536 /*              return NULL; */
2537 /*      } */
2538
2539         o = array_element_get(a, index);
2540
2541         return (jobject) o;
2542 }
2543
2544
2545 /* JVM_GetPrimitiveArrayElement */
2546
2547 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
2548 {
2549         jvalue jv;
2550
2551         log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
2552
2553         jv.l = NULL;
2554
2555         return jv;
2556 }
2557
2558
2559 /* JVM_SetArrayElement */
2560
2561 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
2562 {
2563         java_handle_t *a;
2564         java_handle_t *value;
2565
2566         TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
2567
2568         a     = (java_handle_t *) arr;
2569         value = (java_handle_t *) val;
2570
2571         array_element_set(a, index, value);
2572 }
2573
2574
2575 /* JVM_SetPrimitiveArrayElement */
2576
2577 void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)
2578 {
2579         log_println("JVM_SetPrimitiveArrayElement: IMPLEMENT ME!");
2580 }
2581
2582
2583 /* JVM_NewArray */
2584
2585 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
2586 {
2587         classinfo                 *c;
2588         classinfo                 *pc;
2589         java_handle_t             *a;
2590         java_handle_objectarray_t *oa;
2591
2592         TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
2593
2594         if (eltClass == NULL) {
2595                 exceptions_throw_nullpointerexception();
2596                 return NULL;
2597         }
2598
2599         /* NegativeArraySizeException is checked in builtin_newarray. */
2600
2601         c = LLNI_classinfo_unwrap(eltClass);
2602
2603         /* Create primitive or object array. */
2604
2605         if (class_is_primitive(c)) {
2606                 pc = Primitive::get_arrayclass_by_name(c->name);
2607
2608                 /* void arrays are not allowed. */
2609
2610                 if (pc == NULL) {
2611                         exceptions_throw_illegalargumentexception();
2612                         return NULL;
2613                 }
2614
2615                 a = builtin_newarray(length, pc);
2616
2617                 return (jobject) a;
2618         }
2619         else {
2620                 oa = builtin_anewarray(length, c);
2621
2622                 return (jobject) oa;
2623         }
2624 }
2625
2626
2627 /* JVM_NewMultiArray */
2628
2629 jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
2630 {
2631         classinfo                 *c;
2632         java_handle_intarray_t    *ia;
2633         int32_t                    length;
2634         long                      *dims;
2635         int32_t                    value;
2636         int32_t                    i;
2637         classinfo                 *ac;
2638         java_handle_objectarray_t *a;
2639
2640         TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
2641
2642         if (eltClass == NULL) {
2643                 exceptions_throw_nullpointerexception();
2644                 return NULL;
2645         }
2646
2647         /* NegativeArraySizeException is checked in builtin_newarray. */
2648
2649         c = LLNI_classinfo_unwrap(eltClass);
2650
2651         ia = (java_handle_intarray_t *) dim;
2652
2653         length = array_length_get((java_handle_t *) ia);
2654
2655         /* We check here for exceptions thrown in array_length_get,
2656            otherwise these exceptions get overwritten by the following
2657            IllegalArgumentException. */
2658
2659         if (length < 0)
2660                 return NULL;
2661
2662         if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
2663                 exceptions_throw_illegalargumentexception();
2664                 return NULL;
2665         }
2666
2667         /* XXX This is just a quick hack to get it working. */
2668
2669         dims = MNEW(long, length);
2670
2671         for (i = 0; i < length; i++) {
2672                 value = LLNI_array_direct(ia, i);
2673                 dims[i] = (long) value;
2674         }
2675
2676         /* Create an array-class if necessary. */
2677
2678         if (class_is_primitive(c))
2679                 ac = Primitive::get_arrayclass_by_name(c->name);
2680         else
2681                 ac = class_array_of(c, true);
2682
2683         if (ac == NULL)
2684                 return NULL;
2685
2686         a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
2687
2688         return (jobject) a;
2689 }
2690
2691
2692 /* JVM_InitializeSocketLibrary */
2693
2694 jint JVM_InitializeSocketLibrary()
2695 {
2696         TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
2697
2698         return hpi_initialize_socket_library();
2699 }
2700
2701
2702 /* JVM_Socket */
2703
2704 jint JVM_Socket(jint domain, jint type, jint protocol)
2705 {
2706         TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
2707
2708         return os::socket(domain, type, protocol);
2709 }
2710
2711
2712 /* JVM_SocketClose */
2713
2714 jint JVM_SocketClose(jint fd)
2715 {
2716         TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
2717
2718         return os::close(fd);
2719 }
2720
2721
2722 /* JVM_SocketShutdown */
2723
2724 jint JVM_SocketShutdown(jint fd, jint howto)
2725 {
2726         TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
2727
2728         return os::shutdown(fd, howto);
2729 }
2730
2731
2732 /* JVM_Recv */
2733
2734 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
2735 {
2736         log_println("JVM_Recv: IMPLEMENT ME!");
2737
2738         return 0;
2739 }
2740
2741
2742 /* JVM_Send */
2743
2744 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
2745 {
2746         log_println("JVM_Send: IMPLEMENT ME!");
2747
2748         return 0;
2749 }
2750
2751
2752 /* JVM_Timeout */
2753
2754 jint JVM_Timeout(int fd, long timeout)
2755 {
2756         log_println("JVM_Timeout: IMPLEMENT ME!");
2757
2758         return 0;
2759 }
2760
2761
2762 /* JVM_Listen */
2763
2764 jint JVM_Listen(jint fd, jint count)
2765 {
2766         TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
2767
2768         return os::listen(fd, count);
2769 }
2770
2771
2772 /* JVM_Connect */
2773
2774 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
2775 {
2776         TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
2777
2778         return os::connect(fd, him, len);
2779 }
2780
2781
2782 /* JVM_Bind */
2783
2784 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
2785 {
2786         log_println("JVM_Bind: IMPLEMENT ME!");
2787
2788         return 0;
2789 }
2790
2791
2792 /* JVM_Accept */
2793
2794 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
2795 {
2796         TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
2797
2798         return os::accept(fd, him, (socklen_t *) len);
2799 }
2800
2801
2802 /* JVM_RecvFrom */
2803
2804 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
2805 {
2806         log_println("JVM_RecvFrom: IMPLEMENT ME!");
2807
2808         return 0;
2809 }
2810
2811
2812 /* JVM_GetSockName */
2813
2814 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
2815 {
2816         TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
2817
2818         return os::getsockname(fd, him, (socklen_t *) len);
2819 }
2820
2821
2822 /* JVM_SendTo */
2823
2824 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
2825 {
2826         log_println("JVM_SendTo: IMPLEMENT ME!");
2827
2828         return 0;
2829 }
2830
2831
2832 /* JVM_SocketAvailable */
2833
2834 jint JVM_SocketAvailable(jint fd, jint *pbytes)
2835 {
2836 #if defined(FIONREAD)
2837         int bytes;
2838         int result;
2839
2840         TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
2841
2842         *pbytes = 0;
2843
2844         result = ioctl(fd, FIONREAD, &bytes);
2845
2846         if (result < 0)
2847                 return 0;
2848
2849         *pbytes = bytes;
2850
2851         return 1;
2852 #else
2853 # error FIONREAD not defined
2854 #endif
2855 }
2856
2857
2858 /* JVM_GetSockOpt */
2859
2860 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
2861 {
2862         TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
2863
2864         return os::getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
2865 }
2866
2867
2868 /* JVM_SetSockOpt */
2869
2870 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
2871 {
2872         TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
2873
2874         return os::setsockopt(fd, level, optname, optval, optlen);
2875 }
2876
2877
2878 /* JVM_GetHostName */
2879
2880 int JVM_GetHostName(char *name, int namelen)
2881 {
2882         int result;
2883
2884         TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
2885
2886         result = os::gethostname(name, namelen);
2887
2888         TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
2889
2890         return result;
2891 }
2892
2893
2894 /* JVM_GetHostByAddr */
2895
2896 struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
2897 {
2898         log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
2899
2900         return NULL;
2901 }
2902
2903
2904 /* JVM_GetHostByName */
2905
2906 struct hostent *JVM_GetHostByName(char* name)
2907 {
2908         log_println("JVM_GetHostByName: IMPLEMENT ME!");
2909
2910         return NULL;
2911 }
2912
2913
2914 /* JVM_GetProtoByName */
2915
2916 struct protoent *JVM_GetProtoByName(char* name)
2917 {
2918         log_println("JVM_GetProtoByName: IMPLEMENT ME!");
2919
2920         return NULL;
2921 }
2922
2923
2924 /* JVM_LoadLibrary */
2925
2926 void *JVM_LoadLibrary(const char *name)
2927 {
2928         utf*  u;
2929         void* handle;
2930
2931         TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
2932
2933         u = utf_new_char(name);
2934
2935         handle = native_library_open(u);
2936
2937         TRACEJVMCALLSEXIT(("->%p", handle));
2938
2939         return handle;
2940 }
2941
2942
2943 /* JVM_UnloadLibrary */
2944
2945 void JVM_UnloadLibrary(void* handle)
2946 {
2947         TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
2948
2949         native_library_close(handle);
2950 }
2951
2952
2953 /* JVM_FindLibraryEntry */
2954
2955 void *JVM_FindLibraryEntry(void *handle, const char *name)
2956 {
2957         void* symbol;
2958
2959         TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
2960
2961         symbol = hpi_library->FindLibraryEntry(handle, name);
2962
2963         TRACEJVMCALLSEXIT(("->%p", symbol));
2964
2965         return symbol;
2966 }
2967
2968
2969 /* JVM_IsNaN */
2970
2971 jboolean JVM_IsNaN(jdouble a)
2972 {
2973         log_println("JVM_IsNaN: IMPLEMENT ME!");
2974
2975         return 0;
2976 }
2977
2978
2979 /* JVM_IsSupportedJNIVersion */
2980
2981 jboolean JVM_IsSupportedJNIVersion(jint version)
2982 {
2983         TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
2984
2985         return jni_version_check(version);
2986 }
2987
2988
2989 /* JVM_InternString */
2990
2991 jstring JVM_InternString(JNIEnv *env, jstring str)
2992 {
2993         TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
2994
2995         return (jstring) javastring_intern((java_handle_t *) str);
2996 }
2997
2998
2999 /* JVM_RawMonitorCreate */
3000
3001 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
3002 {
3003         java_object_t *o;
3004
3005         TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
3006
3007         o = NEW(java_object_t);
3008
3009         lock_init_object_lock(o);
3010
3011         return o;
3012 }
3013
3014
3015 /* JVM_RawMonitorDestroy */
3016
3017 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
3018 {
3019         TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
3020
3021         FREE(mon, java_object_t);
3022 }
3023
3024
3025 /* JVM_RawMonitorEnter */
3026
3027 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
3028 {
3029         TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
3030
3031         (void) lock_monitor_enter((java_object_t *) mon);
3032
3033         return 0;
3034 }
3035
3036
3037 /* JVM_RawMonitorExit */
3038
3039 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
3040 {
3041         TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
3042
3043         (void) lock_monitor_exit((java_object_t *) mon);
3044 }
3045
3046
3047 /* JVM_SetPrimitiveFieldValues */
3048
3049 void JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3050 {
3051         log_println("JVM_SetPrimitiveFieldValues: IMPLEMENT ME!");
3052 }
3053
3054
3055 /* JVM_GetPrimitiveFieldValues */
3056
3057 void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)
3058 {
3059         log_println("JVM_GetPrimitiveFieldValues: IMPLEMENT ME!");
3060 }
3061
3062
3063 /* JVM_AccessVMBooleanFlag */
3064
3065 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
3066 {
3067         log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
3068
3069         return 0;
3070 }
3071
3072
3073 /* JVM_AccessVMIntFlag */
3074
3075 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
3076 {
3077         log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
3078
3079         return 0;
3080 }
3081
3082
3083 /* JVM_VMBreakPoint */
3084
3085 void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
3086 {
3087         log_println("JVM_VMBreakPoint: IMPLEMENT ME!");
3088 }
3089
3090
3091 /* JVM_GetClassFields */
3092
3093 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
3094 {
3095         log_println("JVM_GetClassFields: IMPLEMENT ME!");
3096
3097         return NULL;
3098 }
3099
3100
3101 /* JVM_GetClassMethods */
3102
3103 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
3104 {
3105         log_println("JVM_GetClassMethods: IMPLEMENT ME!");
3106
3107         return NULL;
3108 }
3109
3110
3111 /* JVM_GetClassConstructors */
3112
3113 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
3114 {
3115         log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
3116
3117         return NULL;
3118 }
3119
3120
3121 /* JVM_GetClassField */
3122
3123 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
3124 {
3125         log_println("JVM_GetClassField: IMPLEMENT ME!");
3126
3127         return NULL;
3128 }
3129
3130
3131 /* JVM_GetClassMethod */
3132
3133 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
3134 {
3135         log_println("JVM_GetClassMethod: IMPLEMENT ME!");
3136
3137         return NULL;
3138 }
3139
3140
3141 /* JVM_GetClassConstructor */
3142
3143 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
3144 {
3145         log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
3146
3147         return NULL;
3148 }
3149
3150
3151 /* JVM_NewInstance */
3152
3153 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
3154 {
3155         log_println("JVM_NewInstance: IMPLEMENT ME!");
3156
3157         return NULL;
3158 }
3159
3160
3161 /* JVM_GetField */
3162
3163 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
3164 {
3165         log_println("JVM_GetField: IMPLEMENT ME!");
3166
3167         return NULL;
3168 }
3169
3170
3171 /* JVM_GetPrimitiveField */
3172
3173 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
3174 {
3175         jvalue jv;
3176
3177         log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
3178
3179         jv.l = NULL;
3180
3181         return jv;
3182 }
3183
3184
3185 /* JVM_SetField */
3186
3187 void JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val)
3188 {
3189         log_println("JVM_SetField: IMPLEMENT ME!");
3190 }
3191
3192
3193 /* JVM_SetPrimitiveField */
3194
3195 void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, unsigned char vCode)
3196 {
3197         log_println("JVM_SetPrimitiveField: IMPLEMENT ME!");
3198 }
3199
3200
3201 /* JVM_InvokeMethod */
3202
3203 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
3204 {
3205         java_lang_reflect_Method *rm;
3206         classinfo     *c;
3207         int32_t        slot;
3208         int32_t        override;
3209         methodinfo    *m;
3210         java_handle_t *ro;
3211
3212         TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
3213
3214         rm = (java_lang_reflect_Method *) method;
3215
3216         LLNI_field_get_cls(rm, clazz,    c);
3217         LLNI_field_get_val(rm, slot,     slot);
3218         LLNI_field_get_val(rm, override, override);
3219
3220         m = &(c->methods[slot]);
3221
3222         ro = reflect_method_invoke(m, (java_handle_t *) obj, (java_handle_objectarray_t *) args0, override);
3223
3224         return (jobject) ro;
3225 }
3226
3227
3228 /* JVM_NewInstanceFromConstructor */
3229
3230 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
3231 {
3232         java_lang_reflect_Constructor *rc;
3233         classinfo                     *c;
3234         int32_t                        slot;
3235         int32_t                        override;
3236         methodinfo                    *m;
3237         java_handle_t                 *o;
3238
3239         TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
3240
3241         rc = (java_lang_reflect_Constructor *) con;
3242
3243         LLNI_field_get_cls(rc, clazz,    c);
3244         LLNI_field_get_val(rc, slot,     slot);
3245         LLNI_field_get_val(rc, override, override);
3246
3247         m = &(c->methods[slot]);
3248
3249         o = reflect_constructor_newinstance(m, (java_handle_objectarray_t *) args0, override);
3250
3251         return (jobject) o;
3252 }
3253
3254
3255 /* JVM_SupportsCX8 */
3256
3257 jboolean JVM_SupportsCX8()
3258 {
3259         TRACEJVMCALLS(("JVM_SupportsCX8()"));
3260
3261         /* IMPLEMENT ME */
3262
3263         return 0;
3264 }
3265
3266
3267 /* JVM_CX8Field */
3268
3269 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
3270 {
3271         log_println("JVM_CX8Field: IMPLEMENT ME!");
3272
3273         return 0;
3274 }
3275
3276
3277 /* JVM_GetAllThreads */
3278
3279 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
3280 {
3281         log_println("JVM_GetAllThreads: IMPLEMENT ME!");
3282
3283         return NULL;
3284 }
3285
3286
3287 /* JVM_DumpThreads */
3288
3289 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
3290 {
3291         log_println("JVM_DumpThreads: IMPLEMENT ME!");
3292
3293         return NULL;
3294 }
3295
3296
3297 /* JVM_GetManagement */
3298
3299 void *JVM_GetManagement(jint version)
3300 {
3301         TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
3302
3303         /* TODO We current don't support the management interface. */
3304
3305         return NULL;
3306 }
3307
3308
3309 /* JVM_InitAgentProperties */
3310
3311 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
3312 {
3313         log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
3314
3315         return NULL;
3316 }
3317
3318
3319 /* JVM_GetEnclosingMethodInfo */
3320
3321 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
3322 {
3323         classinfo                 *c;
3324         methodinfo                *m;
3325         java_handle_objectarray_t *oa;
3326
3327         TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
3328
3329         c = LLNI_classinfo_unwrap(ofClass);
3330
3331         if ((c == NULL) || class_is_primitive(c))
3332                 return NULL;
3333
3334         m = class_get_enclosingmethod_raw(c);
3335
3336         if (m == NULL)
3337                 return NULL;
3338
3339         oa = builtin_anewarray(3, class_java_lang_Object);
3340
3341         if (oa == NULL)
3342                 return NULL;
3343
3344         array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
3345         array_objectarray_element_set(oa, 1, javastring_new(m->name));
3346         array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
3347
3348         return (jobjectArray) oa;
3349 }
3350
3351
3352 /* JVM_GetThreadStateValues */
3353
3354 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
3355 {
3356         java_handle_intarray_t *ia;
3357
3358         TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
3359                                   env, javaThreadState));
3360
3361         /* If new thread states are added in future JDK and VM versions,
3362            this should check if the JDK version is compatible with thread
3363            states supported by the VM.  Return NULL if not compatible.
3364         
3365            This function must map the VM java_lang_Thread::ThreadStatus
3366            to the Java thread state that the JDK supports. */
3367
3368         switch (javaThreadState) {
3369     case THREAD_STATE_NEW:
3370                 ia = builtin_newarray_int(1);
3371
3372                 if (ia == NULL)
3373                         return NULL;
3374
3375                 array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
3376                 break; 
3377
3378     case THREAD_STATE_RUNNABLE:
3379                 ia = builtin_newarray_int(1);
3380
3381                 if (ia == NULL)
3382                         return NULL;
3383
3384                 array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
3385                 break; 
3386
3387     case THREAD_STATE_BLOCKED:
3388                 ia = builtin_newarray_int(1);
3389
3390                 if (ia == NULL)
3391                         return NULL;
3392
3393                 array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
3394                 break; 
3395
3396     case THREAD_STATE_WAITING:
3397                 ia = builtin_newarray_int(2);
3398
3399                 if (ia == NULL)
3400                         return NULL;
3401
3402                 array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
3403                 /* XXX Implement parked stuff. */
3404 /*              array_intarray_element_set(ia, 1, PARKED); */
3405                 break; 
3406
3407     case THREAD_STATE_TIMED_WAITING:
3408                 ia = builtin_newarray_int(3);
3409
3410                 if (ia == NULL)
3411                         return NULL;
3412
3413                 /* XXX Not sure about that one. */
3414 /*              array_intarray_element_set(ia, 0, SLEEPING); */
3415                 array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
3416                 /* XXX Implement parked stuff. */
3417 /*              array_intarray_element_set(ia, 2, PARKED); */
3418                 break; 
3419
3420     case THREAD_STATE_TERMINATED:
3421                 ia = builtin_newarray_int(1);
3422
3423                 if (ia == NULL)
3424                         return NULL;
3425
3426                 array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
3427                 break; 
3428
3429     default:
3430                 /* Unknown state - probably incompatible JDK version */
3431                 return NULL;
3432         }
3433
3434         return (jintArray) ia;
3435 }
3436
3437
3438 /* JVM_GetThreadStateNames */
3439
3440 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
3441 {
3442         java_handle_intarray_t    *ia;
3443         java_handle_objectarray_t *oa;
3444         java_object_t             *s;
3445
3446         TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
3447                                   env, javaThreadState, values));
3448
3449         ia = (java_handle_intarray_t *) values;
3450
3451         /* If new thread states are added in future JDK and VM versions,
3452            this should check if the JDK version is compatible with thread
3453            states supported by the VM.  Return NULL if not compatible.
3454         
3455            This function must map the VM java_lang_Thread::ThreadStatus
3456            to the Java thread state that the JDK supports. */
3457
3458         if (values == NULL) {
3459                 exceptions_throw_nullpointerexception();
3460                 return NULL;
3461         }
3462
3463         switch (javaThreadState) {
3464     case THREAD_STATE_NEW:
3465                 assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
3466
3467                 oa = builtin_anewarray(1, class_java_lang_String);
3468
3469                 if (oa == NULL)
3470                         return NULL;
3471
3472                 s = javastring_new(utf_new_char("NEW"));
3473
3474                 if (s == NULL)
3475                         return NULL;
3476
3477                 array_objectarray_element_set(oa, 0, s);
3478                 break; 
3479
3480     case THREAD_STATE_RUNNABLE:
3481                 oa = builtin_anewarray(1, class_java_lang_String);
3482
3483                 if (oa == NULL)
3484                         return NULL;
3485
3486                 s = javastring_new(utf_new_char("RUNNABLE"));
3487
3488                 if (s == NULL)
3489                         return NULL;
3490
3491                 array_objectarray_element_set(oa, 0, s);
3492                 break; 
3493
3494     case THREAD_STATE_BLOCKED:
3495                 oa = builtin_anewarray(1, class_java_lang_String);
3496
3497                 if (oa == NULL)
3498                         return NULL;
3499
3500                 s = javastring_new(utf_new_char("BLOCKED"));
3501
3502                 if (s == NULL)
3503                         return NULL;
3504
3505                 array_objectarray_element_set(oa, 0, s);
3506                 break; 
3507
3508     case THREAD_STATE_WAITING:
3509                 oa = builtin_anewarray(2, class_java_lang_String);
3510
3511                 if (oa == NULL)
3512                         return NULL;
3513
3514                 s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
3515 /*              s = javastring_new(utf_new_char("WAITING.PARKED")); */
3516
3517                 if (s == NULL)
3518                         return NULL;
3519
3520                 array_objectarray_element_set(oa, 0, s);
3521 /*              array_objectarray_element_set(oa, 1, s); */
3522                 break; 
3523
3524     case THREAD_STATE_TIMED_WAITING:
3525                 oa = builtin_anewarray(3, class_java_lang_String);
3526
3527                 if (oa == NULL)
3528                         return NULL;
3529
3530 /*              s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
3531                 s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
3532 /*              s = javastring_new(utf_new_char("TIMED_WAITING.PARKED")); */
3533
3534                 if (s == NULL)
3535                         return NULL;
3536
3537 /*              array_objectarray_element_set(oa, 0, s); */
3538                 array_objectarray_element_set(oa, 0, s);
3539 /*              array_objectarray_element_set(oa, 2, s); */
3540                 break; 
3541
3542     case THREAD_STATE_TERMINATED:
3543                 oa = builtin_anewarray(1, class_java_lang_String);
3544
3545                 if (oa == NULL)
3546                         return NULL;
3547
3548                 s = javastring_new(utf_new_char("TERMINATED"));
3549
3550                 if (s == NULL)
3551                         return NULL;
3552
3553                 array_objectarray_element_set(oa, 0, s);
3554                 break; 
3555
3556         default:
3557                 /* Unknown state - probably incompatible JDK version */
3558                 return NULL;
3559         }
3560
3561         return (jobjectArray) oa;
3562 }
3563
3564
3565 /* JVM_GetVersionInfo */
3566
3567 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
3568 {
3569         log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
3570 }
3571
3572
3573 /* OS: JVM_RegisterSignal */
3574
3575 void *JVM_RegisterSignal(jint sig, void *handler)
3576 {
3577         functionptr newHandler;
3578
3579         TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
3580
3581         if (handler == (void *) 2)
3582                 newHandler = (functionptr) signal_thread_handler;
3583         else
3584                 newHandler = (functionptr) (uintptr_t) handler;
3585
3586         switch (sig) {
3587     case SIGILL:
3588     case SIGFPE:
3589     case SIGUSR1:
3590     case SIGSEGV:
3591                 /* These signals are already used by the VM. */
3592                 return (void *) -1;
3593
3594     case SIGQUIT:
3595                 /* This signal is used by the VM to dump thread stacks unless
3596                    ReduceSignalUsage is set, in which case the user is allowed
3597                    to set his own _native_ handler for this signal; thus, in
3598                    either case, we do not allow JVM_RegisterSignal to change
3599                    the handler. */
3600                 return (void *) -1;
3601
3602         case SIGHUP:
3603         case SIGINT:
3604         case SIGTERM:
3605                 break;
3606         }
3607
3608         signal_register_signal(sig, newHandler, SA_RESTART | SA_SIGINFO);
3609
3610         /* XXX Should return old handler. */
3611
3612         return (void *) 2;
3613 }
3614
3615
3616 /* OS: JVM_RaiseSignal */
3617
3618 jboolean JVM_RaiseSignal(jint sig)
3619 {
3620         log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
3621
3622         return false;
3623 }
3624
3625
3626 /* OS: JVM_FindSignal */
3627
3628 jint JVM_FindSignal(const char *name)
3629 {
3630         TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
3631
3632 #if defined(__LINUX__)
3633         if (strcmp(name, "HUP") == 0)
3634                 return SIGHUP;
3635
3636         if (strcmp(name, "INT") == 0)
3637                 return SIGINT;
3638
3639         if (strcmp(name, "TERM") == 0)
3640                 return SIGTERM;
3641 #else
3642 # error not implemented for this OS
3643 #endif
3644
3645         return -1;
3646 }
3647
3648 } // extern "C"
3649
3650
3651 /*
3652  * These are local overrides for various environment variables in Emacs.
3653  * Please do not remove this and leave it at the end of the file, where
3654  * Emacs will automagically detect them.
3655  * ---------------------------------------------------------------------
3656  * Local variables:
3657  * mode: c++
3658  * indent-tabs-mode: t
3659  * c-basic-offset: 4
3660  * tab-width: 4
3661  * End:
3662  */