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