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