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