1 // prims.cc - Code for core of runtime environment.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
26 #include <java-signal.h>
27 #include <java-threads.h>
28 #include <java-interp.h>
32 #include <java/lang/ThreadGroup.h>
37 #include "jvmti-int.h"
40 #ifndef DISABLE_GETENV_PROPERTIES
42 #include <java-props.h>
43 #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
45 #define PROCESS_GCJ_PROPERTIES
46 #endif // DISABLE_GETENV_PROPERTIES
48 #include <java/lang/Class.h>
49 #include <java/lang/ClassLoader.h>
50 #include <java/lang/Runtime.h>
51 #include <java/lang/String.h>
52 #include <java/lang/Thread.h>
53 #include <java/lang/ThreadGroup.h>
54 #include <java/lang/ArrayIndexOutOfBoundsException.h>
55 #include <java/lang/ArithmeticException.h>
56 #include <java/lang/ClassFormatError.h>
57 #include <java/lang/ClassNotFoundException.h>
58 #include <java/lang/InternalError.h>
59 #include <java/lang/NegativeArraySizeException.h>
60 #include <java/lang/NoClassDefFoundError.h>
61 #include <java/lang/NullPointerException.h>
62 #include <java/lang/OutOfMemoryError.h>
63 #include <java/lang/System.h>
64 #include <java/lang/VMClassLoader.h>
65 #include <java/lang/reflect/Modifier.h>
66 #include <java/io/PrintStream.h>
67 #include <java/lang/UnsatisfiedLinkError.h>
68 #include <java/lang/VirtualMachineError.h>
69 #include <gnu/gcj/runtime/ExtensionClassLoader.h>
70 #include <gnu/gcj/runtime/FinalizerThread.h>
71 #include <execution.h>
74 #include <gnu/classpath/jdwp/Jdwp.h>
75 #include <gnu/classpath/jdwp/VMVirtualMachine.h>
78 #include <gnu/java/lang/MainThread.h>
84 // Execution engine for compiled code.
85 _Jv_CompiledEngine _Jv_soleCompiledEngine;
87 // Execution engine for code compiled with -findirect-classes
88 _Jv_IndirectCompiledEngine _Jv_soleIndirectCompiledEngine;
90 // We allocate a single OutOfMemoryError exception which we keep
91 // around for use if we run out of memory.
92 static java::lang::OutOfMemoryError *no_memory;
94 // Number of bytes in largest array object we create. This could be
95 // increased to the largest size_t value, so long as the appropriate
96 // functions are changed to take a size_t argument instead of jint.
97 #define MAX_OBJECT_SIZE (((size_t)1<<31) - 1)
99 // Properties set at compile time.
100 const char **_Jv_Compiler_Properties = NULL;
101 int _Jv_Properties_Count = 0;
103 #ifndef DISABLE_GETENV_PROPERTIES
104 // Property key/value pairs.
105 property_pair *_Jv_Environment_Properties;
108 // Stash the argv pointer to benefit native libraries that need it.
109 const char **_Jv_argv;
113 static bool remoteDebug = false;
115 static char defaultJdwpOptions[] = "";
116 static char *jdwpOptions = defaultJdwpOptions;
118 // Typedefs for JVMTI agent functions.
119 typedef jint jvmti_agent_onload_func (JavaVM *vm, char *options,
121 typedef jint jvmti_agent_onunload_func (JavaVM *vm);
123 // JVMTI agent function pointers.
124 static jvmti_agent_onload_func *jvmti_agentonload = NULL;
125 static jvmti_agent_onunload_func *jvmti_agentonunload = NULL;
126 static char *jvmti_agent_opts;
127 #endif // INTERPRETER
133 // _Jv_argc is 0 if not explicitly initialized.
138 _Jv_GetSafeArg (int index)
140 if (index >=0 && index < _Jv_GetNbArgs ())
141 return _Jv_argv[index];
147 _Jv_SetArgs (int argc, const char **argv)
154 // Pointer to JVMPI notification functions.
155 void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
156 void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
157 void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
161 #if defined (HANDLE_SEGV) || defined(HANDLE_FPE)
162 /* Unblock a signal. Unless we do this, the signal may only be sent
165 unblock_signal (int signum __attribute__ ((__unused__)))
167 #ifdef _POSIX_VERSION
171 sigaddset (&sigs, signum);
172 sigprocmask (SIG_UNBLOCK, &sigs, NULL);
178 SIGNAL_HANDLER (catch_segv)
180 unblock_signal (SIGSEGV);
181 MAKE_THROW_FRAME (nullp);
182 java::lang::NullPointerException *nullp
183 = new java::lang::NullPointerException;
189 SIGNAL_HANDLER (catch_fpe)
191 unblock_signal (SIGFPE);
192 #ifdef HANDLE_DIVIDE_OVERFLOW
193 HANDLE_DIVIDE_OVERFLOW;
195 MAKE_THROW_FRAME (arithexception);
197 java::lang::ArithmeticException *arithexception
198 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
199 throw arithexception;
205 _Jv_equalUtf8Consts (const Utf8Const* a, const Utf8Const *b)
208 const _Jv_ushort *aptr, *bptr;
211 if (a->hash != b->hash)
214 if (b->length != len)
216 aptr = (const _Jv_ushort *)a->data;
217 bptr = (const _Jv_ushort *)b->data;
218 len = (len + 1) >> 1;
220 if (*aptr++ != *bptr++)
225 /* True iff A is equal to STR.
226 HASH is STR->hashCode().
230 _Jv_equal (Utf8Const* a, jstring str, jint hash)
232 if (a->hash != (_Jv_ushort) hash)
234 jint len = str->length();
236 jchar *sptr = _Jv_GetStringChars (str);
237 unsigned char* ptr = (unsigned char*) a->data;
238 unsigned char* limit = ptr + a->length;
241 int ch = UTF8_GET (ptr, limit);
250 /* Like _Jv_equal, but stop after N characters. */
252 _Jv_equaln (Utf8Const *a, jstring str, jint n)
254 jint len = str->length();
256 jchar *sptr = _Jv_GetStringChars (str);
257 unsigned char* ptr = (unsigned char*) a->data;
258 unsigned char* limit = ptr + a->length;
259 for (; n-- > 0; i++, sptr++)
261 int ch = UTF8_GET (ptr, limit);
270 // Determines whether the given Utf8Const object contains
271 // a type which is primitive or some derived form of it, eg.
272 // an array or multi-dimensional array variant.
274 _Jv_isPrimitiveOrDerived(const Utf8Const *a)
276 unsigned char *aptr = (unsigned char *) a->data;
277 unsigned char *alimit = aptr + a->length;
278 int ac = UTF8_GET(aptr, alimit);
280 // Skips any leading array marks.
282 ac = UTF8_GET(aptr, alimit);
284 // There should not be another character. This implies that
285 // the type name is only one character long.
286 if (UTF8_GET(aptr, alimit) == -1)
305 // Find out whether two _Jv_Utf8Const candidates contain the same
307 // The method is written to handle the different formats of classnames.
308 // Eg. "Ljava/lang/Class;", "Ljava.lang.Class;", "java/lang/Class" and
309 // "java.lang.Class" will be seen as equal.
310 // Warning: This function is not smart enough to declare "Z" and "boolean"
311 // and similar cases as equal (and is not meant to be used this way)!
313 _Jv_equalUtf8Classnames (const Utf8Const *a, const Utf8Const *b)
315 // If the class name's length differs by two characters
316 // it is possible that we have candidates which are given
317 // in the two different formats ("Lp1/p2/cn;" vs. "p1/p2/cn")
318 switch (a->length - b->length)
328 unsigned char *aptr = (unsigned char *) a->data;
329 unsigned char *alimit = aptr + a->length;
330 unsigned char *bptr = (unsigned char *) b->data;
331 unsigned char *blimit = bptr + b->length;
333 if (alimit[-1] == ';')
336 if (blimit[-1] == ';')
339 int ac = UTF8_GET(aptr, alimit);
340 int bc = UTF8_GET(bptr, blimit);
342 // Checks whether both strings have the same amount of leading [ characters.
347 ac = UTF8_GET(aptr, alimit);
348 bc = UTF8_GET(bptr, blimit);
355 // Skips leading L character.
357 ac = UTF8_GET(aptr, alimit);
360 bc = UTF8_GET(bptr, blimit);
362 // Compares the remaining characters.
363 while (ac != -1 && bc != -1)
365 // Replaces package separating dots with slashes.
372 // Now classnames differ if there is at least one non-matching
377 ac = UTF8_GET(aptr, alimit);
378 bc = UTF8_GET(bptr, blimit);
384 /* Count the number of Unicode chars encoded in a given Ut8 string. */
386 _Jv_strLengthUtf8(const char* str, int len)
389 unsigned char* limit;
392 ptr = (unsigned char*) str;
395 for (; ptr < limit; str_length++)
397 if (UTF8_GET (ptr, limit) < 0)
403 /* Calculate a hash value for a string encoded in Utf8 format.
404 * This returns the same hash value as specified or java.lang.String.hashCode.
407 _Jv_hashUtf8String (const char* str, int len)
409 unsigned char* ptr = (unsigned char*) str;
410 unsigned char* limit = ptr + len;
415 int ch = UTF8_GET (ptr, limit);
416 /* Updated specification from
417 http://www.javasoft.com/docs/books/jls/clarify.html. */
418 hash = (31 * hash) + ch;
424 _Jv_Utf8Const::init(const char *s, int len)
426 ::memcpy (data, s, len);
429 hash = _Jv_hashUtf8String (s, len) & 0xFFFF;
433 _Jv_makeUtf8Const (const char* s, int len)
438 = (Utf8Const*) _Jv_AllocBytes (_Jv_Utf8Const::space_needed(s, len));
444 _Jv_makeUtf8Const (jstring string)
446 jint hash = string->hashCode ();
447 jint len = _Jv_GetStringUTFLength (string);
449 Utf8Const* m = (Utf8Const*)
450 _Jv_AllocBytes (sizeof(Utf8Const) + len + 1);
455 _Jv_GetStringUTFRegion (string, 0, string->length (), m->data);
465 _Jv_Abort (const char *function, const char *file, int line,
469 _Jv_Abort (const char *, const char *, int, const char *message)
474 "libgcj failure: %s\n in function %s, file %s, line %d\n",
475 message, function, file, line);
477 fprintf (stderr, "libgcj failure: %s\n", message);
484 fail_on_finalization (jobject)
486 JvFail ("object was finalized");
490 _Jv_GCWatch (jobject obj)
492 _Jv_RegisterFinalizer (obj, fail_on_finalization);
496 _Jv_ThrowBadArrayIndex(jint bad_index)
498 throw new java::lang::ArrayIndexOutOfBoundsException
499 (java::lang::String::valueOf (bad_index));
503 _Jv_ThrowNullPointerException ()
505 throw new java::lang::NullPointerException;
508 // Resolve an entry in the constant pool and return the target
511 _Jv_ResolvePoolEntry (jclass this_class, jint index)
513 _Jv_Constants *pool = &this_class->constants;
515 if ((pool->tags[index] & JV_CONSTANT_ResolvedFlag) != 0)
516 return pool->data[index].field->u.addr;
518 JvSynchronize sync (this_class);
519 return (_Jv_Linker::resolve_pool_entry (this_class, index))
524 // Explicitly throw a no memory exception.
525 // The collector calls this when it encounters an out-of-memory condition.
526 void _Jv_ThrowNoMemory()
532 # define JVMPI_NOTIFY_ALLOC(klass,size,obj) \
533 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false)) \
534 jvmpi_notify_alloc(klass,size,obj);
536 jvmpi_notify_alloc(jclass klass, jint size, jobject obj)
538 // Service JVMPI allocation request.
541 event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
543 event.u.obj_alloc.arena_id = 0;
544 event.u.obj_alloc.class_id = (jobjectID) klass;
545 event.u.obj_alloc.is_array = 0;
546 event.u.obj_alloc.size = size;
547 event.u.obj_alloc.obj_id = (jobjectID) obj;
549 // FIXME: This doesn't look right for the Boehm GC. A GC may
550 // already be in progress. _Jv_DisableGC () doesn't wait for it.
551 // More importantly, I don't see the need for disabling GC, since we
552 // blatantly have a pointer to obj on our stack, ensuring that the
553 // object can't be collected. Even for a nonconservative collector,
554 // it appears to me that this must be true, since we are about to
555 // return obj. Isn't this whole approach way too intrusive for
556 // a useful profiling interface? - HB
558 (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
561 #else /* !ENABLE_JVMPI */
562 # define JVMPI_NOTIFY_ALLOC(klass,size,obj) /* do nothing */
565 // Allocate a new object of class KLASS.
566 // First a version that assumes that we have no finalizer, and that
567 // the class is already initialized.
568 // If we know that JVMPI is disabled, this can be replaced by a direct call
569 // to the allocator for the appropriate GC.
571 _Jv_AllocObjectNoInitNoFinalizer (jclass klass)
573 jint size = klass->size ();
574 jobject obj = (jobject) _Jv_AllocObj (size, klass);
575 JVMPI_NOTIFY_ALLOC (klass, size, obj);
579 // And now a version that initializes if necessary.
581 _Jv_AllocObjectNoFinalizer (jclass klass)
583 if (_Jv_IsPhantomClass(klass) )
584 throw new java::lang::NoClassDefFoundError(klass->getName());
586 _Jv_InitClass (klass);
587 jint size = klass->size ();
588 jobject obj = (jobject) _Jv_AllocObj (size, klass);
589 JVMPI_NOTIFY_ALLOC (klass, size, obj);
593 // And now the general version that registers a finalizer if necessary.
595 _Jv_AllocObject (jclass klass)
597 jobject obj = _Jv_AllocObjectNoFinalizer (klass);
599 // We assume that the compiler only generates calls to this routine
600 // if there really is an interesting finalizer.
601 // Unfortunately, we still have to the dynamic test, since there may
602 // be cni calls to this routine.
603 // Note that on IA64 get_finalizer() returns the starting address of the
604 // function, not a function pointer. Thus this still works.
605 if (klass->vtable->get_finalizer ()
606 != java::lang::Object::class$.vtable->get_finalizer ())
607 _Jv_RegisterFinalizer (obj, _Jv_FinalizeObject);
611 // Allocate a String, including variable length storage.
613 _Jv_AllocString(jsize len)
615 using namespace java::lang;
617 jsize sz = sizeof(java::lang::String) + len * sizeof(jchar);
619 // We assert that for strings allocated this way, the data field
620 // will always point to the object itself. Thus there is no reason
621 // for the garbage collector to scan any of it.
622 // Furthermore, we're about to overwrite the string data, so
623 // initialization of the object is not an issue.
625 // String needs no initialization, and there is no finalizer, so
626 // we can go directly to the collector's allocator interface.
627 jstring obj = (jstring) _Jv_AllocPtrFreeObj(sz, &String::class$);
630 obj->boffset = sizeof(java::lang::String);
632 obj->cachedHashCode = 0;
634 JVMPI_NOTIFY_ALLOC (&String::class$, sz, obj);
639 // A version of the above that assumes the object contains no pointers,
640 // and requires no finalization. This can't happen if we need pointers
642 #ifdef JV_HASH_SYNCHRONIZATION
644 _Jv_AllocPtrFreeObject (jclass klass)
646 _Jv_InitClass (klass);
647 jint size = klass->size ();
649 jobject obj = (jobject) _Jv_AllocPtrFreeObj (size, klass);
651 JVMPI_NOTIFY_ALLOC (klass, size, obj);
655 #endif /* JV_HASH_SYNCHRONIZATION */
658 // Allocate a new array of Java objects. Each object is of type
659 // `elementClass'. `init' is used to initialize each slot in the
662 _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
664 // Creating an array of an unresolved type is impossible. So we throw
665 // the NoClassDefFoundError.
666 if ( _Jv_IsPhantomClass(elementClass) )
667 throw new java::lang::NoClassDefFoundError(elementClass->getName());
669 if (__builtin_expect (count < 0, false))
670 throw new java::lang::NegativeArraySizeException;
672 JvAssert (! elementClass->isPrimitive ());
674 // Ensure that elements pointer is properly aligned.
675 jobjectArray obj = NULL;
676 size_t size = (size_t) elements (obj);
677 // Check for overflow.
678 if (__builtin_expect ((size_t) count >
679 (MAX_OBJECT_SIZE - 1 - size) / sizeof (jobject), false))
682 size += count * sizeof (jobject);
684 jclass klass = _Jv_GetArrayClass (elementClass,
685 elementClass->getClassLoaderInternal());
687 obj = (jobjectArray) _Jv_AllocArray (size, klass);
689 jsize *lp = const_cast<jsize *> (&obj->length);
691 // We know the allocator returns zeroed memory. So don't bother
695 jobject *ptr = elements(obj);
702 // Allocate a new array of primitives. ELTYPE is the type of the
703 // element, COUNT is the size of the array.
705 _Jv_NewPrimArray (jclass eltype, jint count)
707 int elsize = eltype->size();
708 if (__builtin_expect (count < 0, false))
709 throw new java::lang::NegativeArraySizeException;
711 JvAssert (eltype->isPrimitive ());
712 jobject dummy = NULL;
713 size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
715 // Check for overflow.
716 if (__builtin_expect ((size_t) count >
717 (MAX_OBJECT_SIZE - size) / elsize, false))
720 jclass klass = _Jv_GetArrayClass (eltype, 0);
722 # ifdef JV_HASH_SYNCHRONIZATION
723 // Since the vtable is always statically allocated,
724 // these are completely pointerfree! Make sure the GC doesn't touch them.
726 (__JArray*) _Jv_AllocPtrFreeObj (size + elsize * count, klass);
727 memset((char *)arr + size, 0, elsize * count);
729 __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass);
730 // Note that we assume we are given zeroed memory by the allocator.
733 jsize *lp = const_cast<jsize *> (&arr->length);
740 _Jv_NewArray (jint type, jint size)
744 case 4: return JvNewBooleanArray (size);
745 case 5: return JvNewCharArray (size);
746 case 6: return JvNewFloatArray (size);
747 case 7: return JvNewDoubleArray (size);
748 case 8: return JvNewByteArray (size);
749 case 9: return JvNewShortArray (size);
750 case 10: return JvNewIntArray (size);
751 case 11: return JvNewLongArray (size);
753 throw new java::lang::InternalError
754 (JvNewStringLatin1 ("invalid type code in _Jv_NewArray"));
757 // Allocate a possibly multi-dimensional array but don't check that
758 // any array length is <0.
760 _Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
762 JvAssert (type->isArray());
763 jclass element_type = type->getComponentType();
765 if (element_type->isPrimitive())
766 result = _Jv_NewPrimArray (element_type, sizes[0]);
768 result = _Jv_NewObjectArray (sizes[0], element_type, NULL);
772 JvAssert (! element_type->isPrimitive());
773 JvAssert (element_type->isArray());
774 jobject *contents = elements ((jobjectArray) result);
775 for (int i = 0; i < sizes[0]; ++i)
776 contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
784 _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
786 for (int i = 0; i < dimensions; ++i)
788 throw new java::lang::NegativeArraySizeException;
790 return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
794 _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
796 // Creating an array of an unresolved type is impossible. So we throw
797 // the NoClassDefFoundError.
798 if (_Jv_IsPhantomClass(array_type))
799 throw new java::lang::NoClassDefFoundError(array_type->getName());
802 jint sizes[dimensions];
803 va_start (args, dimensions);
804 for (int i = 0; i < dimensions; ++i)
806 jint size = va_arg (args, jint);
808 throw new java::lang::NegativeArraySizeException;
813 return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
818 // Ensure 8-byte alignment, for hash synchronization.
819 #define DECLARE_PRIM_TYPE(NAME) \
820 java::lang::Class _Jv_##NAME##Class __attribute__ ((aligned (8)));
822 DECLARE_PRIM_TYPE(byte)
823 DECLARE_PRIM_TYPE(short)
824 DECLARE_PRIM_TYPE(int)
825 DECLARE_PRIM_TYPE(long)
826 DECLARE_PRIM_TYPE(boolean)
827 DECLARE_PRIM_TYPE(char)
828 DECLARE_PRIM_TYPE(float)
829 DECLARE_PRIM_TYPE(double)
830 DECLARE_PRIM_TYPE(void)
833 _Jv_InitPrimClass (jclass cl, const char *cname, char sig, int len)
835 using namespace java::lang::reflect;
837 // We must set the vtable for the class; the Java constructor
839 (*(_Jv_VTable **) cl) = java::lang::Class::class$.vtable;
841 // Initialize the fields we care about. We do this in the same
842 // order they are declared in Class.h.
843 cl->name = _Jv_makeUtf8Const ((char *) cname, -1);
844 cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT;
845 cl->method_count = sig;
846 cl->size_in_bytes = len;
847 cl->vtable = JV_PRIMITIVE_VTABLE;
848 cl->state = JV_STATE_DONE;
853 _Jv_FindClassFromSignature (char *sig, java::lang::ClassLoader *loader,
856 // First count arrays.
864 jclass result = NULL;
868 result = JvPrimClass (byte);
871 result = JvPrimClass (short);
874 result = JvPrimClass (int);
877 result = JvPrimClass (long);
880 result = JvPrimClass (boolean);
883 result = JvPrimClass (char);
886 result = JvPrimClass (float);
889 result = JvPrimClass (double);
892 result = JvPrimClass (void);
897 while (*sig && *sig != ';')
899 // Do nothing if signature appears to be malformed.
902 _Jv_Utf8Const *name = _Jv_makeUtf8Const (save, sig - save);
903 result = _Jv_FindClass (name, loader);
908 // Do nothing -- bad signature.
914 // Not really the "end", but the last valid character that we
923 while (array_count-- > 0)
924 result = _Jv_GetArrayClass (result, loader);
930 _Jv_FindClassFromSignatureNoException (char *sig, java::lang::ClassLoader *loader,
937 klass = _Jv_FindClassFromSignature(sig, loader, endp);
939 catch (java::lang::NoClassDefFoundError *ncdfe)
943 catch (java::lang::ClassNotFoundException *cnfe)
952 JvConvertArgv (int argc, const char **argv)
956 jobjectArray ar = JvNewObjectArray(argc, &java::lang::String::class$, NULL);
957 jobject *ptr = elements(ar);
958 jbyteArray bytes = NULL;
959 for (int i = 0; i < argc; i++)
961 const char *arg = argv[i];
962 int len = strlen (arg);
963 if (bytes == NULL || bytes->length < len)
964 bytes = JvNewByteArray (len);
965 jbyte *bytePtr = elements (bytes);
966 // We assume jbyte == char.
967 memcpy (bytePtr, arg, len);
969 // Now convert using the default encoding.
970 *ptr++ = new java::lang::String (bytes, 0, len);
972 return (JArray<jstring>*) ar;
975 // FIXME: These variables are static so that they will be
976 // automatically scanned by the Boehm collector. This is needed
977 // because with qthreads the collector won't scan the initial stack --
978 // it will only scan the qthreads stacks.
980 // Command line arguments.
981 static JArray<jstring> *arg_vec;
983 // The primary thread.
984 static java::lang::Thread *main_thread;
986 #ifndef DISABLE_GETENV_PROPERTIES
989 next_property_key (char *s, size_t *length)
995 // Skip over whitespace
999 // If we've reached the end, return NULL. Also return NULL if for
1000 // some reason we've come across a malformed property string.
1006 // Determine the length of the property key.
1024 next_property_value (char *s, size_t *length)
1030 while (isspace (*s))
1037 while (isspace (*s))
1040 // Determine the length of the property value.
1059 process_gcj_properties ()
1061 char *props = getenv("GCJ_PROPERTIES");
1066 // Later on we will write \0s into this string. It is simplest to
1067 // just duplicate it here.
1068 props = strdup (props);
1072 size_t property_count = 0;
1074 // Whip through props quickly in order to count the number of
1076 while (p && (p = next_property_key (p, &length)))
1078 // Skip to the end of the key
1081 p = next_property_value (p, &length);
1088 // Allocate an array of property value/key pairs.
1089 _Jv_Environment_Properties =
1090 (property_pair *) malloc (sizeof(property_pair)
1091 * (property_count + 1));
1093 // Go through the properties again, initializing _Jv_Properties
1097 while (p && (p = next_property_key (p, &length)))
1099 _Jv_Environment_Properties[property_count].key = p;
1100 _Jv_Environment_Properties[property_count].key_length = length;
1102 // Skip to the end of the key
1105 p = next_property_value (p, &length);
1107 _Jv_Environment_Properties[property_count].value = p;
1108 _Jv_Environment_Properties[property_count].value_length = length;
1115 memset ((void *) &_Jv_Environment_Properties[property_count],
1116 0, sizeof (property_pair));
1118 // Null terminate the strings.
1119 for (property_pair *prop = &_Jv_Environment_Properties[0];
1123 prop->key[prop->key_length] = 0;
1124 prop->value[prop->value_length] = 0;
1127 #endif // DISABLE_GETENV_PROPERTIES
1131 _Jv_Utf8Const *void_signature;
1132 _Jv_Utf8Const *clinit_name;
1133 _Jv_Utf8Const *init_name;
1134 _Jv_Utf8Const *finit_name;
1136 bool runtimeInitialized = false;
1138 // When true, print debugging information about class loading.
1139 bool verbose_class_flag;
1141 // When true, enable the bytecode verifier and BC-ABI type verification.
1142 bool verifyClasses = true;
1144 // Thread stack size specified by the -Xss runtime argument.
1145 size_t stack_size = 0;
1147 // Start time of the VM
1148 jlong startTime = 0;
1150 // Arguments passed to the VM
1151 JArray<jstring>* vmArgs;
1153 // Currently loaded classes
1154 jint loadedClasses = 0;
1157 jlong unloadedClasses = 0;
1160 // We accept all non-standard options accepted by Sun's java command,
1161 // for compatibility with existing application launch scripts.
1163 parse_x_arg (char* option_string)
1165 if (strlen (option_string) <= 0)
1168 if (! strcmp (option_string, "int"))
1170 // FIXME: this should cause the vm to never load shared objects
1172 else if (! strcmp (option_string, "mixed"))
1174 // FIXME: allow interpreted and native code
1176 else if (! strcmp (option_string, "batch"))
1178 // FIXME: disable background JIT'ing
1180 else if (! strcmp (option_string, "debug"))
1185 else if (! strncmp (option_string, "runjdwp:", 8))
1187 if (strlen (option_string) > 8)
1188 jdwpOptions = &option_string[8];
1192 "libgcj: argument required for JDWP options");
1196 #endif // INTERPRETER
1197 else if (! strncmp (option_string, "bootclasspath:", 14))
1199 // FIXME: add a parse_bootclasspath_arg function
1201 else if (! strncmp (option_string, "bootclasspath/a:", 16))
1204 else if (! strncmp (option_string, "bootclasspath/p:", 16))
1207 else if (! strcmp (option_string, "check:jni"))
1209 // FIXME: enable strict JNI checking
1211 else if (! strcmp (option_string, "future"))
1213 // FIXME: enable strict class file format checks
1215 else if (! strcmp (option_string, "noclassgc"))
1217 // FIXME: disable garbage collection for classes
1219 else if (! strcmp (option_string, "incgc"))
1221 // FIXME: incremental garbage collection
1223 else if (! strncmp (option_string, "loggc:", 6))
1225 if (option_string[6] == '\0')
1228 "libgcj: filename argument expected for loggc option\n");
1231 // FIXME: set gc logging filename
1233 else if (! strncmp (option_string, "ms", 2))
1235 // FIXME: ignore this option until PR 20699 is fixed.
1236 // _Jv_SetInitialHeapSize (option_string + 2);
1238 else if (! strncmp (option_string, "mx", 2))
1239 _Jv_SetMaximumHeapSize (option_string + 2);
1240 else if (! strcmp (option_string, "prof"))
1242 // FIXME: enable profiling of program running in vm
1244 else if (! strncmp (option_string, "runhprof:", 9))
1246 // FIXME: enable specific type of vm profiling. add a
1247 // parse_runhprof_arg function
1249 else if (! strcmp (option_string, "rs"))
1251 // FIXME: reduced system signal usage. disable thread dumps,
1252 // only terminate in response to user-initiated calls,
1253 // e.g. System.exit()
1255 else if (! strncmp (option_string, "ss", 2))
1257 _Jv_SetStackSize (option_string + 2);
1259 else if (! strcmp (option_string, "X:+UseAltSigs"))
1261 // FIXME: use signals other than SIGUSR1 and SIGUSR2
1263 else if (! strcmp (option_string, "share:off"))
1265 // FIXME: don't share class data
1267 else if (! strcmp (option_string, "share:auto"))
1269 // FIXME: share class data where possible
1271 else if (! strcmp (option_string, "share:on"))
1273 // FIXME: fail if impossible to share class data
1284 parse_verbose_args (char* option_string,
1285 bool ignore_unrecognized)
1287 size_t len = sizeof ("-verbose") - 1;
1289 if (strlen (option_string) < len)
1292 if (option_string[len] == ':'
1293 && option_string[len + 1] != '\0')
1295 char* verbose_args = option_string + len + 1;
1299 if (! strncmp (verbose_args,
1300 "gc", sizeof ("gc") - 1))
1302 if (verbose_args[sizeof ("gc") - 1] == '\0'
1303 || verbose_args[sizeof ("gc") - 1] == ',')
1305 // FIXME: we should add functions to boehm-gc that
1306 // toggle GC_print_stats, GC_PRINT_ADDRESS_MAP and
1307 // GC_print_back_height.
1308 verbose_args += sizeof ("gc") - 1;
1313 fprintf (stderr, "libgcj: unknown verbose option: %s\n",
1318 else if (! strncmp (verbose_args,
1320 sizeof ("class") - 1))
1322 if (verbose_args[sizeof ("class") - 1] == '\0'
1323 || verbose_args[sizeof ("class") - 1] == ',')
1325 gcj::verbose_class_flag = true;
1326 verbose_args += sizeof ("class") - 1;
1329 goto verbose_arg_err;
1331 else if (! strncmp (verbose_args, "jni",
1332 sizeof ("jni") - 1))
1334 if (verbose_args[sizeof ("jni") - 1] == '\0'
1335 || verbose_args[sizeof ("jni") - 1] == ',')
1337 // FIXME: enable JNI messages.
1338 verbose_args += sizeof ("jni") - 1;
1341 goto verbose_arg_err;
1343 else if (ignore_unrecognized
1344 && verbose_args[0] == 'X')
1346 // ignore unrecognized non-standard verbose option
1347 while (verbose_args[0] != '\0'
1348 && verbose_args[0] != ',')
1351 else if (verbose_args[0] == ',')
1356 goto verbose_arg_err;
1358 if (verbose_args[0] == ',')
1361 while (verbose_args[0] != '\0');
1363 else if (option_string[len] == 'g'
1364 && option_string[len + 1] == 'c'
1365 && option_string[len + 2] == '\0')
1367 // FIXME: we should add functions to boehm-gc that
1368 // toggle GC_print_stats, GC_PRINT_ADDRESS_MAP and
1369 // GC_print_back_height.
1372 else if (option_string[len] == '\0')
1374 gcj::verbose_class_flag = true;
1379 // unrecognized option beginning with -verbose
1386 // This function loads the agent functions for JVMTI from the library indicated
1387 // by name. It returns a negative value on failure, the value of which
1388 // indicates where ltdl failed, it also prints an error message.
1390 load_jvmti_agent (const char *name)
1396 "libgcj: Error in ltdl init while loading agent library.\n");
1400 lt_dlhandle lib = lt_dlopenext (name);
1404 "libgcj: Error opening agent library.\n");
1411 = (jvmti_agent_onload_func *) lt_dlsym (lib, "Agent_OnLoad");
1413 if (!jvmti_agentonload)
1416 "libgcj: Error finding agent function in library %s.\n",
1425 = (jvmti_agent_onunload_func *) lt_dlsym (lib, "Agent_OnUnload");
1432 fprintf (stderr, "libgcj: Library %s not found in library path.\n", name);
1436 #endif /* USE_LTDL */
1438 // If LTDL cannot be used, return an error code indicating this.
1441 #endif // INTERPRETER
1444 parse_init_args (JvVMInitArgs* vm_args)
1446 // if _Jv_Compiler_Properties is non-NULL then it needs to be
1447 // re-allocated dynamically.
1448 if (_Jv_Compiler_Properties)
1450 const char** props = _Jv_Compiler_Properties;
1451 _Jv_Compiler_Properties = NULL;
1453 for (int i = 0; props[i]; i++)
1455 _Jv_Compiler_Properties = (const char**) _Jv_Realloc
1456 (_Jv_Compiler_Properties,
1457 (_Jv_Properties_Count + 1) * sizeof (const char*));
1458 _Jv_Compiler_Properties[_Jv_Properties_Count++] = props[i];
1462 if (vm_args == NULL)
1465 for (int i = 0; i < vm_args->nOptions; ++i)
1467 char* option_string = vm_args->options[i].optionString;
1469 if (! strcmp (option_string, "vfprintf")
1470 || ! strcmp (option_string, "exit")
1471 || ! strcmp (option_string, "abort"))
1473 // FIXME: we are required to recognize these, but for
1474 // now we don't handle them in any way.
1477 else if (! strncmp (option_string,
1478 "-verbose", sizeof ("-verbose") - 1))
1480 jint result = parse_verbose_args (option_string,
1481 vm_args->ignoreUnrecognized);
1485 else if (! strncmp (option_string, "-D", 2))
1487 _Jv_Compiler_Properties = (const char**) _Jv_Realloc
1488 (_Jv_Compiler_Properties,
1489 (_Jv_Properties_Count + 1) * sizeof (char*));
1491 _Jv_Compiler_Properties[_Jv_Properties_Count++] =
1492 strdup (option_string + 2);
1497 else if (! strncmp (option_string, "-agentlib", sizeof ("-agentlib") - 1))
1501 if (strlen(option_string) > (sizeof ("-agentlib:") - 1))
1502 strPtr = &option_string[sizeof ("-agentlib:") - 1];
1506 "libgcj: Malformed agentlib argument %s: expected lib name\n",
1511 // These are optional arguments to pass to the agent library.
1512 jvmti_agent_opts = strchr (strPtr, '=');
1514 if (! strncmp (strPtr, "jdwp", 4))
1516 // We want to run JDWP here so set the correct variables.
1518 jdwpOptions = ++jvmti_agent_opts;
1524 if (jvmti_agent_opts == NULL)
1525 nameLength = strlen (strPtr);
1528 nameLength = jvmti_agent_opts - strPtr;
1532 char lib_name[nameLength + 3 + 1];
1533 strcpy (lib_name, "lib");
1534 strncat (lib_name, strPtr, nameLength);
1536 jint result = load_jvmti_agent (lib_name);
1543 // Mark JVMTI active
1544 JVMTI::enabled = true;
1549 else if (! strncmp (option_string, "-agentpath:",
1550 sizeof ("-agentpath:") - 1))
1554 if (strlen(option_string) > 10)
1555 strPtr = &option_string[10];
1559 "libgcj: Malformed agentlib argument %s: expected lib path\n",
1564 // These are optional arguments to pass to the agent library.
1565 jvmti_agent_opts = strchr (strPtr, '=');
1569 if (jvmti_agent_opts == NULL)
1570 nameLength = strlen (strPtr);
1573 nameLength = jvmti_agent_opts - strPtr;
1577 char lib_name[nameLength + 3 + 1];
1578 strcpy (lib_name, "lib");
1579 strncat (lib_name, strPtr, nameLength);
1580 jint result = load_jvmti_agent (strPtr);
1587 // Mark JVMTI active
1588 JVMTI::enabled = true;
1591 #endif // INTERPRETER
1595 if (option_string[0] == '_')
1596 r = parse_x_arg (option_string + 1);
1597 else if (! strncmp (option_string, "-X", 2))
1598 r = parse_x_arg (option_string + 2);
1600 if (r == -1 && ! vm_args->ignoreUnrecognized)
1602 fprintf (stderr, "libgcj: unknown option: %s\n", option_string);
1611 _Jv_CreateJavaVM (JvVMInitArgs* vm_args)
1613 using namespace gcj;
1615 if (runtimeInitialized)
1618 runtimeInitialized = true;
1619 startTime = _Jv_platform_gettimeofday();
1621 jint result = parse_init_args (vm_args);
1625 PROCESS_GCJ_PROPERTIES;
1627 /* Threads must be initialized before the GC, so that it inherits the
1631 _Jv_InitializeSyncMutex ();
1634 _Jv_InitInterpreter ();
1645 /* Initialize Utf8 constants declared in jvm.h. */
1646 void_signature = _Jv_makeUtf8Const ("()V", 3);
1647 clinit_name = _Jv_makeUtf8Const ("<clinit>", 8);
1648 init_name = _Jv_makeUtf8Const ("<init>", 6);
1649 finit_name = _Jv_makeUtf8Const ("finit$", 6);
1651 /* Initialize built-in classes to represent primitive TYPEs. */
1652 _Jv_InitPrimClass (&_Jv_byteClass, "byte", 'B', 1);
1653 _Jv_InitPrimClass (&_Jv_shortClass, "short", 'S', 2);
1654 _Jv_InitPrimClass (&_Jv_intClass, "int", 'I', 4);
1655 _Jv_InitPrimClass (&_Jv_longClass, "long", 'J', 8);
1656 _Jv_InitPrimClass (&_Jv_booleanClass, "boolean", 'Z', 1);
1657 _Jv_InitPrimClass (&_Jv_charClass, "char", 'C', 2);
1658 _Jv_InitPrimClass (&_Jv_floatClass, "float", 'F', 4);
1659 _Jv_InitPrimClass (&_Jv_doubleClass, "double", 'D', 8);
1660 _Jv_InitPrimClass (&_Jv_voidClass, "void", 'V', 0);
1662 // We have to initialize this fairly early, to avoid circular class
1663 // initialization. In particular we want to start the
1664 // initialization of ClassLoader before we start the initialization
1665 // of VMClassLoader.
1666 _Jv_InitClass (&java::lang::ClassLoader::class$);
1668 // Set up the system class loader and the bootstrap class loader.
1669 gnu::gcj::runtime::ExtensionClassLoader::initialize();
1670 java::lang::VMClassLoader::initialize(JvNewStringLatin1(TOOLEXECLIBDIR));
1672 _Jv_RegisterBootstrapPackages();
1674 no_memory = new java::lang::OutOfMemoryError;
1677 LTDL_SET_PRELOADED_SYMBOLS ();
1680 _Jv_platform_initialize ();
1688 _Jv_GCInitializeFinalizers (&::gnu::gcj::runtime::FinalizerThread::finalizerReady);
1690 // Start the GC finalizer thread. A VirtualMachineError can be
1691 // thrown by the runtime if, say, threads aren't available.
1694 using namespace gnu::gcj::runtime;
1695 FinalizerThread *ft = new FinalizerThread ();
1698 catch (java::lang::VirtualMachineError *ignore)
1702 runtimeInitialized = true;
1708 _Jv_RunMain (JvVMInitArgs *vm_args, jclass klass, const char *name, int argc,
1709 const char **argv, bool is_jar)
1711 #ifndef DISABLE_MAIN_ARGS
1712 _Jv_SetArgs (argc, argv);
1715 java::lang::Runtime *runtime = NULL;
1719 if (_Jv_CreateJavaVM (vm_args) < 0)
1721 fprintf (stderr, "libgcj: couldn't create virtual machine\n");
1725 if (vm_args == NULL)
1726 gcj::vmArgs = JvConvertArgv(0, NULL);
1729 const char* vmArgs[vm_args->nOptions];
1730 const char** vmPtr = vmArgs;
1731 struct _Jv_VMOption* optionPtr = vm_args->options;
1732 for (int i = 0; i < vm_args->nOptions; ++i)
1733 *vmPtr++ = (*optionPtr++).optionString;
1734 gcj::vmArgs = JvConvertArgv(vm_args->nOptions, vmArgs);
1737 // Get the Runtime here. We want to initialize it before searching
1738 // for `main'; that way it will be set up if `main' is a JNI method.
1739 runtime = java::lang::Runtime::getRuntime ();
1741 #ifdef DISABLE_MAIN_ARGS
1742 arg_vec = JvConvertArgv (0, 0);
1744 arg_vec = JvConvertArgv (argc - 1, argv + 1);
1747 using namespace gnu::java::lang;
1749 main_thread = new MainThread (klass, arg_vec);
1751 main_thread = new MainThread (JvNewStringUTF (name),
1753 _Jv_AttachCurrentThread (main_thread);
1756 // Start JVMTI if an agent function has been found.
1757 if (jvmti_agentonload)
1758 (*jvmti_agentonload) (_Jv_GetJavaVM (), jvmti_agent_opts, NULL);
1763 using namespace gnu::classpath::jdwp;
1764 VMVirtualMachine::initialize ();
1765 Jdwp *jdwp = new Jdwp ();
1766 jdwp->setDaemon (true);
1767 jdwp->configure (JvNewStringLatin1 (jdwpOptions));
1770 // Wait for JDWP to initialize and start
1774 if (JVMTI_REQUESTED_EVENT (VMInit))
1775 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_INIT, main_thread);
1776 #endif // INTERPRETER
1778 catch (java::lang::Throwable *t)
1780 java::lang::System::err->println (JvNewStringLatin1
1781 ("Exception during runtime initialization"));
1782 t->printStackTrace();
1784 java::lang::Runtime::exitNoChecksAccessor (1);
1785 // In case the runtime creation failed.
1789 _Jv_ThreadRun (main_thread);
1793 if (JVMTI_REQUESTED_EVENT (VMDeath))
1795 java::lang::Thread *thread = java::lang::Thread::currentThread ();
1796 JNIEnv *jni_env = _Jv_GetCurrentJNIEnv ();
1797 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_DEATH, thread, jni_env);
1800 // Run JVMTI AgentOnUnload if it exists and an agent is loaded.
1801 if (jvmti_agentonunload)
1802 (*jvmti_agentonunload) (_Jv_GetJavaVM ());
1803 #endif // INTERPRETER
1805 // If we got here then something went wrong, as MainThread is not
1806 // supposed to terminate.
1811 _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
1814 _Jv_RunMain (NULL, klass, name, argc, argv, is_jar);
1818 JvRunMain (jclass klass, int argc, const char **argv)
1820 _Jv_RunMain (klass, NULL, argc, argv, false);
1824 JvRunMainName (const char *name, int argc, const char **argv)
1826 _Jv_RunMain (NULL, name, argc, argv, false);
1831 // Parse a string and return a heap size.
1833 parse_memory_size (const char *spec)
1836 unsigned long val = strtoul (spec, &end, 10);
1837 if (*end == 'k' || *end == 'K')
1839 else if (*end == 'm' || *end == 'M')
1841 return (size_t) val;
1844 // Set the initial heap size. This might be ignored by the GC layer.
1845 // This must be called before _Jv_RunMain.
1847 _Jv_SetInitialHeapSize (const char *arg)
1849 size_t size = parse_memory_size (arg);
1850 _Jv_GCSetInitialHeapSize (size);
1853 // Set the maximum heap size. This might be ignored by the GC layer.
1854 // This must be called before _Jv_RunMain.
1856 _Jv_SetMaximumHeapSize (const char *arg)
1858 size_t size = parse_memory_size (arg);
1859 _Jv_GCSetMaximumHeapSize (size);
1863 _Jv_SetStackSize (const char *arg)
1865 size_t size = parse_memory_size (arg);
1866 gcj::stack_size = size;
1870 _Jv_Malloc (jsize size)
1872 if (__builtin_expect (size == 0, false))
1874 void *ptr = malloc ((size_t) size);
1875 if (__builtin_expect (ptr == NULL, false))
1881 _Jv_Realloc (void *ptr, jsize size)
1883 if (__builtin_expect (size == 0, false))
1885 ptr = realloc (ptr, (size_t) size);
1886 if (__builtin_expect (ptr == NULL, false))
1892 _Jv_MallocUnchecked (jsize size)
1894 if (__builtin_expect (size == 0, false))
1896 return malloc ((size_t) size);
1900 _Jv_Free (void* ptr)
1907 // In theory, these routines can be #ifdef'd away on machines which
1908 // support divide overflow signals. However, we never know if some
1909 // code might have been compiled with "-fuse-divide-subroutine", so we
1910 // always include them in libgcj.
1913 _Jv_divI (jint dividend, jint divisor)
1915 if (__builtin_expect (divisor == 0, false))
1917 java::lang::ArithmeticException *arithexception
1918 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1919 throw arithexception;
1922 if (dividend == (jint) 0x80000000L && divisor == -1)
1925 return dividend / divisor;
1929 _Jv_remI (jint dividend, jint divisor)
1931 if (__builtin_expect (divisor == 0, false))
1933 java::lang::ArithmeticException *arithexception
1934 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1935 throw arithexception;
1938 if (dividend == (jint) 0x80000000L && divisor == -1)
1941 return dividend % divisor;
1945 _Jv_divJ (jlong dividend, jlong divisor)
1947 if (__builtin_expect (divisor == 0, false))
1949 java::lang::ArithmeticException *arithexception
1950 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1951 throw arithexception;
1954 if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
1957 return dividend / divisor;
1961 _Jv_remJ (jlong dividend, jlong divisor)
1963 if (__builtin_expect (divisor == 0, false))
1965 java::lang::ArithmeticException *arithexception
1966 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1967 throw arithexception;
1970 if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
1973 return dividend % divisor;
1978 // Return true if SELF_KLASS can access a field or method in
1979 // OTHER_KLASS. The field or method's access flags are specified in
1982 _Jv_CheckAccess (jclass self_klass, jclass other_klass, jint flags)
1984 using namespace java::lang::reflect;
1985 return ((self_klass == other_klass)
1986 || ((flags & Modifier::PUBLIC) != 0)
1987 || (((flags & Modifier::PROTECTED) != 0)
1988 && _Jv_IsAssignableFromSlow (self_klass, other_klass))
1989 || (((flags & Modifier::PRIVATE) == 0)
1990 && _Jv_ClassNameSamePackage (self_klass->name,
1991 other_klass->name)));
1994 // Prepend GCJ_VERSIONED_LIBDIR to a module search path stored in a C
1995 // char array, if the path is not already prefixed by
1996 // GCJ_VERSIONED_LIBDIR. Return a newly JvMalloc'd char buffer. The
1997 // result should be freed using JvFree.
1999 _Jv_PrependVersionedLibdir (char* libpath)
2003 if (libpath && libpath[0] != '\0')
2005 if (! strncmp (libpath,
2006 GCJ_VERSIONED_LIBDIR,
2007 sizeof (GCJ_VERSIONED_LIBDIR) - 1))
2009 // LD_LIBRARY_PATH is already prefixed with
2010 // GCJ_VERSIONED_LIBDIR.
2011 retval = (char*) _Jv_Malloc (strlen (libpath) + 1);
2012 strcpy (retval, libpath);
2016 // LD_LIBRARY_PATH is not prefixed with
2017 // GCJ_VERSIONED_LIBDIR.
2019 path_sep[0] = (char) _Jv_platform_path_separator;
2021 jsize total = ((sizeof (GCJ_VERSIONED_LIBDIR) - 1)
2022 + 1 /* path separator */ + strlen (libpath) + 1);
2023 retval = (char*) _Jv_Malloc (total);
2024 strcpy (retval, GCJ_VERSIONED_LIBDIR);
2025 strcat (retval, path_sep);
2026 strcat (retval, libpath);
2031 // LD_LIBRARY_PATH was not specified or is empty.
2032 retval = (char*) _Jv_Malloc (sizeof (GCJ_VERSIONED_LIBDIR));
2033 strcpy (retval, GCJ_VERSIONED_LIBDIR);