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