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
41 #include <java-props.h>
42 #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
44 #define PROCESS_GCJ_PROPERTIES
45 #endif // DISABLE_GETENV_PROPERTIES
47 #include <java/lang/Class.h>
48 #include <java/lang/ClassLoader.h>
49 #include <java/lang/Runtime.h>
50 #include <java/lang/String.h>
51 #include <java/lang/Thread.h>
52 #include <java/lang/ThreadGroup.h>
53 #include <java/lang/ArrayIndexOutOfBoundsException.h>
54 #include <java/lang/ArithmeticException.h>
55 #include <java/lang/ClassFormatError.h>
56 #include <java/lang/ClassNotFoundException.h>
57 #include <java/lang/InternalError.h>
58 #include <java/lang/NegativeArraySizeException.h>
59 #include <java/lang/NoClassDefFoundError.h>
60 #include <java/lang/NullPointerException.h>
61 #include <java/lang/OutOfMemoryError.h>
62 #include <java/lang/System.h>
63 #include <java/lang/VMClassLoader.h>
64 #include <java/lang/reflect/Modifier.h>
65 #include <java/io/PrintStream.h>
66 #include <java/lang/UnsatisfiedLinkError.h>
67 #include <java/lang/VirtualMachineError.h>
68 #include <gnu/gcj/runtime/ExtensionClassLoader.h>
69 #include <gnu/gcj/runtime/FinalizerThread.h>
70 #include <execution.h>
73 #include <gnu/classpath/jdwp/Jdwp.h>
74 #include <gnu/classpath/jdwp/VMVirtualMachine.h>
77 #include <gnu/java/lang/MainThread.h>
83 // Execution engine for compiled code.
84 _Jv_CompiledEngine _Jv_soleCompiledEngine;
86 // Execution engine for code compiled with -findirect-classes
87 _Jv_IndirectCompiledEngine _Jv_soleIndirectCompiledEngine;
89 // We allocate a single OutOfMemoryError exception which we keep
90 // around for use if we run out of memory.
91 static java::lang::OutOfMemoryError *no_memory;
93 // Number of bytes in largest array object we create. This could be
94 // increased to the largest size_t value, so long as the appropriate
95 // functions are changed to take a size_t argument instead of jint.
96 #define MAX_OBJECT_SIZE (((size_t)1<<31) - 1)
98 // Properties set at compile time.
99 const char **_Jv_Compiler_Properties = NULL;
100 int _Jv_Properties_Count = 0;
102 #ifndef DISABLE_GETENV_PROPERTIES
103 // Property key/value pairs.
104 property_pair *_Jv_Environment_Properties;
107 // Stash the argv pointer to benefit native libraries that need it.
108 const char **_Jv_argv;
112 static bool remoteDebug = false;
114 static char defaultJdwpOptions[] = "";
115 static char *jdwpOptions = defaultJdwpOptions;
117 // Typedefs for JVMTI agent functions.
118 typedef jint jvmti_agent_onload_func (JavaVM *vm, char *options,
120 typedef jint jvmti_agent_onunload_func (JavaVM *vm);
122 // JVMTI agent function pointers.
123 static jvmti_agent_onload_func *jvmti_agentonload = NULL;
124 static jvmti_agent_onunload_func *jvmti_agentonunload = NULL;
125 static char *jvmti_agent_opts;
126 #endif // INTERPRETER
132 // _Jv_argc is 0 if not explicitly initialized.
137 _Jv_GetSafeArg (int index)
139 if (index >=0 && index < _Jv_GetNbArgs ())
140 return _Jv_argv[index];
146 _Jv_SetArgs (int argc, const char **argv)
153 // Pointer to JVMPI notification functions.
154 void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
155 void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
156 void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
160 #if defined (HANDLE_SEGV) || defined(HANDLE_FPE)
161 /* Unblock a signal. Unless we do this, the signal may only be sent
164 unblock_signal (int signum __attribute__ ((__unused__)))
166 #ifdef _POSIX_VERSION
170 sigaddset (&sigs, signum);
171 sigprocmask (SIG_UNBLOCK, &sigs, NULL);
177 SIGNAL_HANDLER (catch_segv)
179 unblock_signal (SIGSEGV);
180 MAKE_THROW_FRAME (nullp);
181 java::lang::NullPointerException *nullp
182 = new java::lang::NullPointerException;
188 SIGNAL_HANDLER (catch_fpe)
190 unblock_signal (SIGFPE);
191 #ifdef HANDLE_DIVIDE_OVERFLOW
192 HANDLE_DIVIDE_OVERFLOW;
194 MAKE_THROW_FRAME (arithexception);
196 java::lang::ArithmeticException *arithexception
197 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
198 throw arithexception;
204 _Jv_equalUtf8Consts (const Utf8Const* a, const Utf8Const *b)
207 const _Jv_ushort *aptr, *bptr;
210 if (a->hash != b->hash)
213 if (b->length != len)
215 aptr = (const _Jv_ushort *)a->data;
216 bptr = (const _Jv_ushort *)b->data;
217 len = (len + 1) >> 1;
219 if (*aptr++ != *bptr++)
224 /* True iff A is equal to STR.
225 HASH is STR->hashCode().
229 _Jv_equal (Utf8Const* a, jstring str, jint hash)
231 if (a->hash != (_Jv_ushort) hash)
233 jint len = str->length();
235 jchar *sptr = _Jv_GetStringChars (str);
236 unsigned char* ptr = (unsigned char*) a->data;
237 unsigned char* limit = ptr + a->length;
240 int ch = UTF8_GET (ptr, limit);
249 /* Like _Jv_equal, but stop after N characters. */
251 _Jv_equaln (Utf8Const *a, jstring str, jint n)
253 jint len = str->length();
255 jchar *sptr = _Jv_GetStringChars (str);
256 unsigned char* ptr = (unsigned char*) a->data;
257 unsigned char* limit = ptr + a->length;
258 for (; n-- > 0; i++, sptr++)
260 int ch = UTF8_GET (ptr, limit);
269 // Determines whether the given Utf8Const object contains
270 // a type which is primitive or some derived form of it, eg.
271 // an array or multi-dimensional array variant.
273 _Jv_isPrimitiveOrDerived(const Utf8Const *a)
275 unsigned char *aptr = (unsigned char *) a->data;
276 unsigned char *alimit = aptr + a->length;
277 int ac = UTF8_GET(aptr, alimit);
279 // Skips any leading array marks.
281 ac = UTF8_GET(aptr, alimit);
283 // There should not be another character. This implies that
284 // the type name is only one character long.
285 if (UTF8_GET(aptr, alimit) == -1)
304 // Find out whether two _Jv_Utf8Const candidates contain the same
306 // The method is written to handle the different formats of classnames.
307 // Eg. "Ljava/lang/Class;", "Ljava.lang.Class;", "java/lang/Class" and
308 // "java.lang.Class" will be seen as equal.
309 // Warning: This function is not smart enough to declare "Z" and "boolean"
310 // and similar cases as equal (and is not meant to be used this way)!
312 _Jv_equalUtf8Classnames (const Utf8Const *a, const Utf8Const *b)
314 // If the class name's length differs by two characters
315 // it is possible that we have candidates which are given
316 // in the two different formats ("Lp1/p2/cn;" vs. "p1/p2/cn")
317 switch (a->length - b->length)
327 unsigned char *aptr = (unsigned char *) a->data;
328 unsigned char *alimit = aptr + a->length;
329 unsigned char *bptr = (unsigned char *) b->data;
330 unsigned char *blimit = bptr + b->length;
332 if (alimit[-1] == ';')
335 if (blimit[-1] == ';')
338 int ac = UTF8_GET(aptr, alimit);
339 int bc = UTF8_GET(bptr, blimit);
341 // Checks whether both strings have the same amount of leading [ characters.
346 ac = UTF8_GET(aptr, alimit);
347 bc = UTF8_GET(bptr, blimit);
354 // Skips leading L character.
356 ac = UTF8_GET(aptr, alimit);
359 bc = UTF8_GET(bptr, blimit);
361 // Compares the remaining characters.
362 while (ac != -1 && bc != -1)
364 // Replaces package separating dots with slashes.
371 // Now classnames differ if there is at least one non-matching
376 ac = UTF8_GET(aptr, alimit);
377 bc = UTF8_GET(bptr, blimit);
383 /* Count the number of Unicode chars encoded in a given Ut8 string. */
385 _Jv_strLengthUtf8(const char* str, int len)
388 unsigned char* limit;
391 ptr = (unsigned char*) str;
394 for (; ptr < limit; str_length++)
396 if (UTF8_GET (ptr, limit) < 0)
402 /* Calculate a hash value for a string encoded in Utf8 format.
403 * This returns the same hash value as specified or java.lang.String.hashCode.
406 _Jv_hashUtf8String (const char* str, int len)
408 unsigned char* ptr = (unsigned char*) str;
409 unsigned char* limit = ptr + len;
414 int ch = UTF8_GET (ptr, limit);
415 /* Updated specification from
416 http://www.javasoft.com/docs/books/jls/clarify.html. */
417 hash = (31 * hash) + ch;
423 _Jv_Utf8Const::init(const char *s, int len)
425 ::memcpy (data, s, len);
428 hash = _Jv_hashUtf8String (s, len) & 0xFFFF;
432 _Jv_makeUtf8Const (const char* s, int len)
437 = (Utf8Const*) _Jv_AllocBytes (_Jv_Utf8Const::space_needed(s, len));
443 _Jv_makeUtf8Const (jstring string)
445 jint hash = string->hashCode ();
446 jint len = _Jv_GetStringUTFLength (string);
448 Utf8Const* m = (Utf8Const*)
449 _Jv_AllocBytes (sizeof(Utf8Const) + len + 1);
454 _Jv_GetStringUTFRegion (string, 0, string->length (), m->data);
464 _Jv_Abort (const char *function, const char *file, int line,
468 _Jv_Abort (const char *, const char *, int, const char *message)
473 "libgcj failure: %s\n in function %s, file %s, line %d\n",
474 message, function, file, line);
476 fprintf (stderr, "libgcj failure: %s\n", message);
483 fail_on_finalization (jobject)
485 JvFail ("object was finalized");
489 _Jv_GCWatch (jobject obj)
491 _Jv_RegisterFinalizer (obj, fail_on_finalization);
495 _Jv_ThrowBadArrayIndex(jint bad_index)
497 throw new java::lang::ArrayIndexOutOfBoundsException
498 (java::lang::String::valueOf (bad_index));
502 _Jv_ThrowNullPointerException ()
504 throw new java::lang::NullPointerException;
507 // Resolve an entry in the constant pool and return the target
510 _Jv_ResolvePoolEntry (jclass this_class, jint index)
512 _Jv_Constants *pool = &this_class->constants;
514 if ((pool->tags[index] & JV_CONSTANT_ResolvedFlag) != 0)
515 return pool->data[index].field->u.addr;
517 JvSynchronize sync (this_class);
518 return (_Jv_Linker::resolve_pool_entry (this_class, index))
523 // Explicitly throw a no memory exception.
524 // The collector calls this when it encounters an out-of-memory condition.
525 void _Jv_ThrowNoMemory()
531 # define JVMPI_NOTIFY_ALLOC(klass,size,obj) \
532 if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false)) \
533 jvmpi_notify_alloc(klass,size,obj);
535 jvmpi_notify_alloc(jclass klass, jint size, jobject obj)
537 // Service JVMPI allocation request.
540 event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
542 event.u.obj_alloc.arena_id = 0;
543 event.u.obj_alloc.class_id = (jobjectID) klass;
544 event.u.obj_alloc.is_array = 0;
545 event.u.obj_alloc.size = size;
546 event.u.obj_alloc.obj_id = (jobjectID) obj;
548 // FIXME: This doesn't look right for the Boehm GC. A GC may
549 // already be in progress. _Jv_DisableGC () doesn't wait for it.
550 // More importantly, I don't see the need for disabling GC, since we
551 // blatantly have a pointer to obj on our stack, ensuring that the
552 // object can't be collected. Even for a nonconservative collector,
553 // it appears to me that this must be true, since we are about to
554 // return obj. Isn't this whole approach way too intrusive for
555 // a useful profiling interface? - HB
557 (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
560 #else /* !ENABLE_JVMPI */
561 # define JVMPI_NOTIFY_ALLOC(klass,size,obj) /* do nothing */
564 // Allocate a new object of class KLASS.
565 // First a version that assumes that we have no finalizer, and that
566 // the class is already initialized.
567 // If we know that JVMPI is disabled, this can be replaced by a direct call
568 // to the allocator for the appropriate GC.
570 _Jv_AllocObjectNoInitNoFinalizer (jclass klass)
572 jint size = klass->size ();
573 jobject obj = (jobject) _Jv_AllocObj (size, klass);
574 JVMPI_NOTIFY_ALLOC (klass, size, obj);
578 // And now a version that initializes if necessary.
580 _Jv_AllocObjectNoFinalizer (jclass klass)
582 if (_Jv_IsPhantomClass(klass) )
583 throw new java::lang::NoClassDefFoundError(klass->getName());
585 _Jv_InitClass (klass);
586 jint size = klass->size ();
587 jobject obj = (jobject) _Jv_AllocObj (size, klass);
588 JVMPI_NOTIFY_ALLOC (klass, size, obj);
592 // And now the general version that registers a finalizer if necessary.
594 _Jv_AllocObject (jclass klass)
596 jobject obj = _Jv_AllocObjectNoFinalizer (klass);
598 // We assume that the compiler only generates calls to this routine
599 // if there really is an interesting finalizer.
600 // Unfortunately, we still have to the dynamic test, since there may
601 // be cni calls to this routine.
602 // Note that on IA64 get_finalizer() returns the starting address of the
603 // function, not a function pointer. Thus this still works.
604 if (klass->vtable->get_finalizer ()
605 != java::lang::Object::class$.vtable->get_finalizer ())
606 _Jv_RegisterFinalizer (obj, _Jv_FinalizeObject);
610 // Allocate a String, including variable length storage.
612 _Jv_AllocString(jsize len)
614 using namespace java::lang;
616 jsize sz = sizeof(java::lang::String) + len * sizeof(jchar);
618 // We assert that for strings allocated this way, the data field
619 // will always point to the object itself. Thus there is no reason
620 // for the garbage collector to scan any of it.
621 // Furthermore, we're about to overwrite the string data, so
622 // initialization of the object is not an issue.
624 // String needs no initialization, and there is no finalizer, so
625 // we can go directly to the collector's allocator interface.
626 jstring obj = (jstring) _Jv_AllocPtrFreeObj(sz, &String::class$);
629 obj->boffset = sizeof(java::lang::String);
631 obj->cachedHashCode = 0;
633 JVMPI_NOTIFY_ALLOC (&String::class$, sz, obj);
638 // A version of the above that assumes the object contains no pointers,
639 // and requires no finalization. This can't happen if we need pointers
641 #ifdef JV_HASH_SYNCHRONIZATION
643 _Jv_AllocPtrFreeObject (jclass klass)
645 _Jv_InitClass (klass);
646 jint size = klass->size ();
648 jobject obj = (jobject) _Jv_AllocPtrFreeObj (size, klass);
650 JVMPI_NOTIFY_ALLOC (klass, size, obj);
654 #endif /* JV_HASH_SYNCHRONIZATION */
657 // Allocate a new array of Java objects. Each object is of type
658 // `elementClass'. `init' is used to initialize each slot in the
661 _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
663 // Creating an array of an unresolved type is impossible. So we throw
664 // the NoClassDefFoundError.
665 if ( _Jv_IsPhantomClass(elementClass) )
666 throw new java::lang::NoClassDefFoundError(elementClass->getName());
668 if (__builtin_expect (count < 0, false))
669 throw new java::lang::NegativeArraySizeException;
671 JvAssert (! elementClass->isPrimitive ());
673 // Ensure that elements pointer is properly aligned.
674 jobjectArray obj = NULL;
675 size_t size = (size_t) elements (obj);
676 // Check for overflow.
677 if (__builtin_expect ((size_t) count >
678 (MAX_OBJECT_SIZE - 1 - size) / sizeof (jobject), false))
681 size += count * sizeof (jobject);
683 jclass klass = _Jv_GetArrayClass (elementClass,
684 elementClass->getClassLoaderInternal());
686 obj = (jobjectArray) _Jv_AllocArray (size, klass);
688 jsize *lp = const_cast<jsize *> (&obj->length);
690 // We know the allocator returns zeroed memory. So don't bother
694 jobject *ptr = elements(obj);
701 // Allocate a new array of primitives. ELTYPE is the type of the
702 // element, COUNT is the size of the array.
704 _Jv_NewPrimArray (jclass eltype, jint count)
706 int elsize = eltype->size();
707 if (__builtin_expect (count < 0, false))
708 throw new java::lang::NegativeArraySizeException;
710 JvAssert (eltype->isPrimitive ());
711 jobject dummy = NULL;
712 size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
714 // Check for overflow.
715 if (__builtin_expect ((size_t) count >
716 (MAX_OBJECT_SIZE - size) / elsize, false))
719 jclass klass = _Jv_GetArrayClass (eltype, 0);
721 # ifdef JV_HASH_SYNCHRONIZATION
722 // Since the vtable is always statically allocated,
723 // these are completely pointerfree! Make sure the GC doesn't touch them.
725 (__JArray*) _Jv_AllocPtrFreeObj (size + elsize * count, klass);
726 memset((char *)arr + size, 0, elsize * count);
728 __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass);
729 // Note that we assume we are given zeroed memory by the allocator.
732 jsize *lp = const_cast<jsize *> (&arr->length);
739 _Jv_NewArray (jint type, jint size)
743 case 4: return JvNewBooleanArray (size);
744 case 5: return JvNewCharArray (size);
745 case 6: return JvNewFloatArray (size);
746 case 7: return JvNewDoubleArray (size);
747 case 8: return JvNewByteArray (size);
748 case 9: return JvNewShortArray (size);
749 case 10: return JvNewIntArray (size);
750 case 11: return JvNewLongArray (size);
752 throw new java::lang::InternalError
753 (JvNewStringLatin1 ("invalid type code in _Jv_NewArray"));
756 // Allocate a possibly multi-dimensional array but don't check that
757 // any array length is <0.
759 _Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
761 JvAssert (type->isArray());
762 jclass element_type = type->getComponentType();
764 if (element_type->isPrimitive())
765 result = _Jv_NewPrimArray (element_type, sizes[0]);
767 result = _Jv_NewObjectArray (sizes[0], element_type, NULL);
771 JvAssert (! element_type->isPrimitive());
772 JvAssert (element_type->isArray());
773 jobject *contents = elements ((jobjectArray) result);
774 for (int i = 0; i < sizes[0]; ++i)
775 contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
783 _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
785 for (int i = 0; i < dimensions; ++i)
787 throw new java::lang::NegativeArraySizeException;
789 return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
793 _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
795 // Creating an array of an unresolved type is impossible. So we throw
796 // the NoClassDefFoundError.
797 if (_Jv_IsPhantomClass(array_type))
798 throw new java::lang::NoClassDefFoundError(array_type->getName());
801 jint sizes[dimensions];
802 va_start (args, dimensions);
803 for (int i = 0; i < dimensions; ++i)
805 jint size = va_arg (args, jint);
807 throw new java::lang::NegativeArraySizeException;
812 return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
817 // Ensure 8-byte alignment, for hash synchronization.
818 #define DECLARE_PRIM_TYPE(NAME) \
819 java::lang::Class _Jv_##NAME##Class __attribute__ ((aligned (8)));
821 DECLARE_PRIM_TYPE(byte)
822 DECLARE_PRIM_TYPE(short)
823 DECLARE_PRIM_TYPE(int)
824 DECLARE_PRIM_TYPE(long)
825 DECLARE_PRIM_TYPE(boolean)
826 DECLARE_PRIM_TYPE(char)
827 DECLARE_PRIM_TYPE(float)
828 DECLARE_PRIM_TYPE(double)
829 DECLARE_PRIM_TYPE(void)
832 _Jv_InitPrimClass (jclass cl, const char *cname, char sig, int len)
834 using namespace java::lang::reflect;
836 // We must set the vtable for the class; the Java constructor
838 (*(_Jv_VTable **) cl) = java::lang::Class::class$.vtable;
840 // Initialize the fields we care about. We do this in the same
841 // order they are declared in Class.h.
842 cl->name = _Jv_makeUtf8Const ((char *) cname, -1);
843 cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT;
844 cl->method_count = sig;
845 cl->size_in_bytes = len;
846 cl->vtable = JV_PRIMITIVE_VTABLE;
847 cl->state = JV_STATE_DONE;
852 _Jv_FindClassFromSignature (char *sig, java::lang::ClassLoader *loader,
855 // First count arrays.
863 jclass result = NULL;
867 result = JvPrimClass (byte);
870 result = JvPrimClass (short);
873 result = JvPrimClass (int);
876 result = JvPrimClass (long);
879 result = JvPrimClass (boolean);
882 result = JvPrimClass (char);
885 result = JvPrimClass (float);
888 result = JvPrimClass (double);
891 result = JvPrimClass (void);
896 while (*sig && *sig != ';')
898 // Do nothing if signature appears to be malformed.
901 _Jv_Utf8Const *name = _Jv_makeUtf8Const (save, sig - save);
902 result = _Jv_FindClass (name, loader);
907 // Do nothing -- bad signature.
913 // Not really the "end", but the last valid character that we
922 while (array_count-- > 0)
923 result = _Jv_GetArrayClass (result, loader);
929 _Jv_FindClassFromSignatureNoException (char *sig, java::lang::ClassLoader *loader,
936 klass = _Jv_FindClassFromSignature(sig, loader, endp);
938 catch (java::lang::NoClassDefFoundError *ncdfe)
942 catch (java::lang::ClassNotFoundException *cnfe)
951 JvConvertArgv (int argc, const char **argv)
955 jobjectArray ar = JvNewObjectArray(argc, &java::lang::String::class$, NULL);
956 jobject *ptr = elements(ar);
957 jbyteArray bytes = NULL;
958 for (int i = 0; i < argc; i++)
960 const char *arg = argv[i];
961 int len = strlen (arg);
962 if (bytes == NULL || bytes->length < len)
963 bytes = JvNewByteArray (len);
964 jbyte *bytePtr = elements (bytes);
965 // We assume jbyte == char.
966 memcpy (bytePtr, arg, len);
968 // Now convert using the default encoding.
969 *ptr++ = new java::lang::String (bytes, 0, len);
971 return (JArray<jstring>*) ar;
974 // FIXME: These variables are static so that they will be
975 // automatically scanned by the Boehm collector. This is needed
976 // because with qthreads the collector won't scan the initial stack --
977 // it will only scan the qthreads stacks.
979 // Command line arguments.
980 static JArray<jstring> *arg_vec;
982 // The primary thread.
983 static java::lang::Thread *main_thread;
985 #ifndef DISABLE_GETENV_PROPERTIES
987 #define c_isspace(c) (memchr (" \t\n\r\v\f", c, 6) != NULL)
990 next_property_key (char *s, size_t *length)
996 // Skip over whitespace
997 while (c_isspace (*s))
1000 // If we've reached the end, return NULL. Also return NULL if for
1001 // some reason we've come across a malformed property string.
1007 // Determine the length of the property key.
1009 && ! c_isspace (s[l])
1025 next_property_value (char *s, size_t *length)
1031 while (c_isspace (*s))
1038 while (c_isspace (*s))
1041 // Determine the length of the property value.
1043 && ! c_isspace (s[l])
1060 process_gcj_properties ()
1062 char *props = getenv("GCJ_PROPERTIES");
1067 // Later on we will write \0s into this string. It is simplest to
1068 // just duplicate it here.
1069 props = strdup (props);
1073 size_t property_count = 0;
1075 // Whip through props quickly in order to count the number of
1077 while (p && (p = next_property_key (p, &length)))
1079 // Skip to the end of the key
1082 p = next_property_value (p, &length);
1089 // Allocate an array of property value/key pairs.
1090 _Jv_Environment_Properties =
1091 (property_pair *) malloc (sizeof(property_pair)
1092 * (property_count + 1));
1094 // Go through the properties again, initializing _Jv_Properties
1098 while (p && (p = next_property_key (p, &length)))
1100 _Jv_Environment_Properties[property_count].key = p;
1101 _Jv_Environment_Properties[property_count].key_length = length;
1103 // Skip to the end of the key
1106 p = next_property_value (p, &length);
1108 _Jv_Environment_Properties[property_count].value = p;
1109 _Jv_Environment_Properties[property_count].value_length = length;
1116 memset ((void *) &_Jv_Environment_Properties[property_count],
1117 0, sizeof (property_pair));
1119 // Null terminate the strings.
1120 for (property_pair *prop = &_Jv_Environment_Properties[0];
1124 prop->key[prop->key_length] = 0;
1125 prop->value[prop->value_length] = 0;
1128 #endif // DISABLE_GETENV_PROPERTIES
1132 _Jv_Utf8Const *void_signature;
1133 _Jv_Utf8Const *clinit_name;
1134 _Jv_Utf8Const *init_name;
1135 _Jv_Utf8Const *finit_name;
1137 bool runtimeInitialized = false;
1139 // When true, print debugging information about class loading.
1140 bool verbose_class_flag;
1142 // When true, enable the bytecode verifier and BC-ABI type verification.
1143 bool verifyClasses = true;
1145 // Thread stack size specified by the -Xss runtime argument.
1146 size_t stack_size = 0;
1148 // Start time of the VM
1149 jlong startTime = 0;
1151 // Arguments passed to the VM
1152 JArray<jstring>* vmArgs;
1154 // Currently loaded classes
1155 jint loadedClasses = 0;
1158 jlong unloadedClasses = 0;
1161 // We accept all non-standard options accepted by Sun's java command,
1162 // for compatibility with existing application launch scripts.
1164 parse_x_arg (char* option_string)
1166 if (strlen (option_string) <= 0)
1169 if (! strcmp (option_string, "int"))
1171 // FIXME: this should cause the vm to never load shared objects
1173 else if (! strcmp (option_string, "mixed"))
1175 // FIXME: allow interpreted and native code
1177 else if (! strcmp (option_string, "batch"))
1179 // FIXME: disable background JIT'ing
1181 else if (! strcmp (option_string, "debug"))
1186 else if (! strncmp (option_string, "runjdwp:", 8))
1188 if (strlen (option_string) > 8)
1189 jdwpOptions = &option_string[8];
1193 "libgcj: argument required for JDWP options");
1197 #endif // INTERPRETER
1198 else if (! strncmp (option_string, "bootclasspath:", 14))
1200 // FIXME: add a parse_bootclasspath_arg function
1202 else if (! strncmp (option_string, "bootclasspath/a:", 16))
1205 else if (! strncmp (option_string, "bootclasspath/p:", 16))
1208 else if (! strcmp (option_string, "check:jni"))
1210 // FIXME: enable strict JNI checking
1212 else if (! strcmp (option_string, "future"))
1214 // FIXME: enable strict class file format checks
1216 else if (! strcmp (option_string, "noclassgc"))
1218 // FIXME: disable garbage collection for classes
1220 else if (! strcmp (option_string, "incgc"))
1222 // FIXME: incremental garbage collection
1224 else if (! strncmp (option_string, "loggc:", 6))
1226 if (option_string[6] == '\0')
1229 "libgcj: filename argument expected for loggc option\n");
1232 // FIXME: set gc logging filename
1234 else if (! strncmp (option_string, "ms", 2))
1236 // FIXME: ignore this option until PR 20699 is fixed.
1237 // _Jv_SetInitialHeapSize (option_string + 2);
1239 else if (! strncmp (option_string, "mx", 2))
1240 _Jv_SetMaximumHeapSize (option_string + 2);
1241 else if (! strcmp (option_string, "prof"))
1243 // FIXME: enable profiling of program running in vm
1245 else if (! strncmp (option_string, "runhprof:", 9))
1247 // FIXME: enable specific type of vm profiling. add a
1248 // parse_runhprof_arg function
1250 else if (! strcmp (option_string, "rs"))
1252 // FIXME: reduced system signal usage. disable thread dumps,
1253 // only terminate in response to user-initiated calls,
1254 // e.g. System.exit()
1256 else if (! strncmp (option_string, "ss", 2))
1258 _Jv_SetStackSize (option_string + 2);
1260 else if (! strcmp (option_string, "X:+UseAltSigs"))
1262 // FIXME: use signals other than SIGUSR1 and SIGUSR2
1264 else if (! strcmp (option_string, "share:off"))
1266 // FIXME: don't share class data
1268 else if (! strcmp (option_string, "share:auto"))
1270 // FIXME: share class data where possible
1272 else if (! strcmp (option_string, "share:on"))
1274 // FIXME: fail if impossible to share class data
1285 parse_verbose_args (char* option_string,
1286 bool ignore_unrecognized)
1288 size_t len = sizeof ("-verbose") - 1;
1290 if (strlen (option_string) < len)
1293 if (option_string[len] == ':'
1294 && option_string[len + 1] != '\0')
1296 char* verbose_args = option_string + len + 1;
1300 if (! strncmp (verbose_args,
1301 "gc", sizeof ("gc") - 1))
1303 if (verbose_args[sizeof ("gc") - 1] == '\0'
1304 || verbose_args[sizeof ("gc") - 1] == ',')
1306 // FIXME: we should add functions to boehm-gc that
1307 // toggle GC_print_stats, GC_PRINT_ADDRESS_MAP and
1308 // GC_print_back_height.
1309 verbose_args += sizeof ("gc") - 1;
1314 fprintf (stderr, "libgcj: unknown verbose option: %s\n",
1319 else if (! strncmp (verbose_args,
1321 sizeof ("class") - 1))
1323 if (verbose_args[sizeof ("class") - 1] == '\0'
1324 || verbose_args[sizeof ("class") - 1] == ',')
1326 gcj::verbose_class_flag = true;
1327 verbose_args += sizeof ("class") - 1;
1330 goto verbose_arg_err;
1332 else if (! strncmp (verbose_args, "jni",
1333 sizeof ("jni") - 1))
1335 if (verbose_args[sizeof ("jni") - 1] == '\0'
1336 || verbose_args[sizeof ("jni") - 1] == ',')
1338 // FIXME: enable JNI messages.
1339 verbose_args += sizeof ("jni") - 1;
1342 goto verbose_arg_err;
1344 else if (ignore_unrecognized
1345 && verbose_args[0] == 'X')
1347 // ignore unrecognized non-standard verbose option
1348 while (verbose_args[0] != '\0'
1349 && verbose_args[0] != ',')
1352 else if (verbose_args[0] == ',')
1357 goto verbose_arg_err;
1359 if (verbose_args[0] == ',')
1362 while (verbose_args[0] != '\0');
1364 else if (option_string[len] == 'g'
1365 && option_string[len + 1] == 'c'
1366 && option_string[len + 2] == '\0')
1368 // FIXME: we should add functions to boehm-gc that
1369 // toggle GC_print_stats, GC_PRINT_ADDRESS_MAP and
1370 // GC_print_back_height.
1373 else if (option_string[len] == '\0')
1375 gcj::verbose_class_flag = true;
1380 // unrecognized option beginning with -verbose
1387 // This function loads the agent functions for JVMTI from the library indicated
1388 // by name. It returns a negative value on failure, the value of which
1389 // indicates where ltdl failed, it also prints an error message.
1391 load_jvmti_agent (const char *name)
1397 "libgcj: Error in ltdl init while loading agent library.\n");
1401 lt_dlhandle lib = lt_dlopenext (name);
1405 "libgcj: Error opening agent library.\n");
1412 = (jvmti_agent_onload_func *) lt_dlsym (lib, "Agent_OnLoad");
1414 if (!jvmti_agentonload)
1417 "libgcj: Error finding agent function in library %s.\n",
1426 = (jvmti_agent_onunload_func *) lt_dlsym (lib, "Agent_OnUnload");
1433 fprintf (stderr, "libgcj: Library %s not found in library path.\n", name);
1437 #endif /* USE_LTDL */
1439 // If LTDL cannot be used, return an error code indicating this.
1442 #endif // INTERPRETER
1445 parse_init_args (JvVMInitArgs* vm_args)
1447 // if _Jv_Compiler_Properties is non-NULL then it needs to be
1448 // re-allocated dynamically.
1449 if (_Jv_Compiler_Properties)
1451 const char** props = _Jv_Compiler_Properties;
1452 _Jv_Compiler_Properties = NULL;
1454 for (int i = 0; props[i]; i++)
1456 _Jv_Compiler_Properties = (const char**) _Jv_Realloc
1457 (_Jv_Compiler_Properties,
1458 (_Jv_Properties_Count + 1) * sizeof (const char*));
1459 _Jv_Compiler_Properties[_Jv_Properties_Count++] = props[i];
1463 if (vm_args == NULL)
1466 for (int i = 0; i < vm_args->nOptions; ++i)
1468 char* option_string = vm_args->options[i].optionString;
1470 if (! strcmp (option_string, "vfprintf")
1471 || ! strcmp (option_string, "exit")
1472 || ! strcmp (option_string, "abort"))
1474 // FIXME: we are required to recognize these, but for
1475 // now we don't handle them in any way.
1478 else if (! strncmp (option_string,
1479 "-verbose", sizeof ("-verbose") - 1))
1481 jint result = parse_verbose_args (option_string,
1482 vm_args->ignoreUnrecognized);
1486 else if (! strncmp (option_string, "-D", 2))
1488 _Jv_Compiler_Properties = (const char**) _Jv_Realloc
1489 (_Jv_Compiler_Properties,
1490 (_Jv_Properties_Count + 1) * sizeof (char*));
1492 _Jv_Compiler_Properties[_Jv_Properties_Count++] =
1493 strdup (option_string + 2);
1498 else if (! strncmp (option_string, "-agentlib", sizeof ("-agentlib") - 1))
1502 if (strlen(option_string) > (sizeof ("-agentlib:") - 1))
1503 strPtr = &option_string[sizeof ("-agentlib:") - 1];
1507 "libgcj: Malformed agentlib argument %s: expected lib name\n",
1512 // These are optional arguments to pass to the agent library.
1513 jvmti_agent_opts = strchr (strPtr, '=');
1515 if (! strncmp (strPtr, "jdwp", 4))
1517 // We want to run JDWP here so set the correct variables.
1519 jdwpOptions = ++jvmti_agent_opts;
1525 if (jvmti_agent_opts == NULL)
1526 nameLength = strlen (strPtr);
1529 nameLength = jvmti_agent_opts - strPtr;
1533 char lib_name[nameLength + 3 + 1];
1534 strcpy (lib_name, "lib");
1535 strncat (lib_name, strPtr, nameLength);
1537 jint result = load_jvmti_agent (lib_name);
1544 // Mark JVMTI active
1545 JVMTI::enabled = true;
1550 else if (! strncmp (option_string, "-agentpath:",
1551 sizeof ("-agentpath:") - 1))
1555 if (strlen(option_string) > 10)
1556 strPtr = &option_string[10];
1560 "libgcj: Malformed agentlib argument %s: expected lib path\n",
1565 // These are optional arguments to pass to the agent library.
1566 jvmti_agent_opts = strchr (strPtr, '=');
1570 if (jvmti_agent_opts == NULL)
1571 nameLength = strlen (strPtr);
1574 nameLength = jvmti_agent_opts - strPtr;
1578 char lib_name[nameLength + 3 + 1];
1579 strcpy (lib_name, "lib");
1580 strncat (lib_name, strPtr, nameLength);
1581 jint result = load_jvmti_agent (strPtr);
1588 // Mark JVMTI active
1589 JVMTI::enabled = true;
1592 #endif // INTERPRETER
1596 if (option_string[0] == '_')
1597 r = parse_x_arg (option_string + 1);
1598 else if (! strncmp (option_string, "-X", 2))
1599 r = parse_x_arg (option_string + 2);
1601 if (r == -1 && ! vm_args->ignoreUnrecognized)
1603 fprintf (stderr, "libgcj: unknown option: %s\n", option_string);
1612 _Jv_CreateJavaVM (JvVMInitArgs* vm_args)
1614 using namespace gcj;
1616 if (runtimeInitialized)
1619 runtimeInitialized = true;
1620 startTime = _Jv_platform_gettimeofday();
1622 jint result = parse_init_args (vm_args);
1626 PROCESS_GCJ_PROPERTIES;
1628 /* Threads must be initialized before the GC, so that it inherits the
1632 _Jv_InitializeSyncMutex ();
1635 _Jv_InitInterpreter ();
1646 /* Initialize Utf8 constants declared in jvm.h. */
1647 void_signature = _Jv_makeUtf8Const ("()V", 3);
1648 clinit_name = _Jv_makeUtf8Const ("<clinit>", 8);
1649 init_name = _Jv_makeUtf8Const ("<init>", 6);
1650 finit_name = _Jv_makeUtf8Const ("finit$", 6);
1652 /* Initialize built-in classes to represent primitive TYPEs. */
1653 _Jv_InitPrimClass (&_Jv_byteClass, "byte", 'B', 1);
1654 _Jv_InitPrimClass (&_Jv_shortClass, "short", 'S', 2);
1655 _Jv_InitPrimClass (&_Jv_intClass, "int", 'I', 4);
1656 _Jv_InitPrimClass (&_Jv_longClass, "long", 'J', 8);
1657 _Jv_InitPrimClass (&_Jv_booleanClass, "boolean", 'Z', 1);
1658 _Jv_InitPrimClass (&_Jv_charClass, "char", 'C', 2);
1659 _Jv_InitPrimClass (&_Jv_floatClass, "float", 'F', 4);
1660 _Jv_InitPrimClass (&_Jv_doubleClass, "double", 'D', 8);
1661 _Jv_InitPrimClass (&_Jv_voidClass, "void", 'V', 0);
1663 // We have to initialize this fairly early, to avoid circular class
1664 // initialization. In particular we want to start the
1665 // initialization of ClassLoader before we start the initialization
1666 // of VMClassLoader.
1667 _Jv_InitClass (&java::lang::ClassLoader::class$);
1669 // Set up the system class loader and the bootstrap class loader.
1670 gnu::gcj::runtime::ExtensionClassLoader::initialize();
1671 java::lang::VMClassLoader::initialize(JvNewStringLatin1(TOOLEXECLIBDIR));
1673 _Jv_RegisterBootstrapPackages();
1675 no_memory = new java::lang::OutOfMemoryError;
1678 LTDL_SET_PRELOADED_SYMBOLS ();
1681 _Jv_platform_initialize ();
1689 _Jv_GCInitializeFinalizers (&::gnu::gcj::runtime::FinalizerThread::finalizerReady);
1691 // Start the GC finalizer thread. A VirtualMachineError can be
1692 // thrown by the runtime if, say, threads aren't available.
1695 using namespace gnu::gcj::runtime;
1696 FinalizerThread *ft = new FinalizerThread ();
1699 catch (java::lang::VirtualMachineError *ignore)
1703 runtimeInitialized = true;
1709 _Jv_RunMain (JvVMInitArgs *vm_args, jclass klass, const char *name, int argc,
1710 const char **argv, bool is_jar)
1712 #ifndef DISABLE_MAIN_ARGS
1713 _Jv_SetArgs (argc, argv);
1716 java::lang::Runtime *runtime = NULL;
1720 if (_Jv_CreateJavaVM (vm_args) < 0)
1722 fprintf (stderr, "libgcj: couldn't create virtual machine\n");
1726 if (vm_args == NULL)
1727 gcj::vmArgs = JvConvertArgv(0, NULL);
1730 const char* vmArgs[vm_args->nOptions];
1731 const char** vmPtr = vmArgs;
1732 struct _Jv_VMOption* optionPtr = vm_args->options;
1733 for (int i = 0; i < vm_args->nOptions; ++i)
1734 *vmPtr++ = (*optionPtr++).optionString;
1735 gcj::vmArgs = JvConvertArgv(vm_args->nOptions, vmArgs);
1738 // Get the Runtime here. We want to initialize it before searching
1739 // for `main'; that way it will be set up if `main' is a JNI method.
1740 runtime = java::lang::Runtime::getRuntime ();
1742 #ifdef DISABLE_MAIN_ARGS
1743 arg_vec = JvConvertArgv (0, 0);
1745 arg_vec = JvConvertArgv (argc - 1, argv + 1);
1748 using namespace gnu::java::lang;
1750 main_thread = new MainThread (klass, arg_vec);
1752 main_thread = new MainThread (JvNewStringUTF (name),
1754 _Jv_AttachCurrentThread (main_thread);
1757 // Start JVMTI if an agent function has been found.
1758 if (jvmti_agentonload)
1759 (*jvmti_agentonload) (_Jv_GetJavaVM (), jvmti_agent_opts, NULL);
1764 using namespace gnu::classpath::jdwp;
1765 VMVirtualMachine::initialize ();
1766 Jdwp *jdwp = new Jdwp ();
1767 jdwp->setDaemon (true);
1768 jdwp->configure (JvNewStringLatin1 (jdwpOptions));
1771 // Wait for JDWP to initialize and start
1775 if (JVMTI_REQUESTED_EVENT (VMInit))
1776 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_INIT, main_thread);
1777 #endif // INTERPRETER
1779 catch (java::lang::Throwable *t)
1781 java::lang::System::err->println (JvNewStringLatin1
1782 ("Exception during runtime initialization"));
1783 t->printStackTrace();
1785 java::lang::Runtime::exitNoChecksAccessor (1);
1786 // In case the runtime creation failed.
1790 _Jv_ThreadRun (main_thread);
1794 if (JVMTI_REQUESTED_EVENT (VMDeath))
1796 java::lang::Thread *thread = java::lang::Thread::currentThread ();
1797 JNIEnv *jni_env = _Jv_GetCurrentJNIEnv ();
1798 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_DEATH, thread, jni_env);
1801 // Run JVMTI AgentOnUnload if it exists and an agent is loaded.
1802 if (jvmti_agentonunload)
1803 (*jvmti_agentonunload) (_Jv_GetJavaVM ());
1804 #endif // INTERPRETER
1806 // If we got here then something went wrong, as MainThread is not
1807 // supposed to terminate.
1812 _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
1815 _Jv_RunMain (NULL, klass, name, argc, argv, is_jar);
1819 JvRunMain (jclass klass, int argc, const char **argv)
1821 _Jv_RunMain (klass, NULL, argc, argv, false);
1825 JvRunMainName (const char *name, int argc, const char **argv)
1827 _Jv_RunMain (NULL, name, argc, argv, false);
1832 // Parse a string and return a heap size.
1834 parse_memory_size (const char *spec)
1837 unsigned long val = strtoul (spec, &end, 10);
1838 if (*end == 'k' || *end == 'K')
1840 else if (*end == 'm' || *end == 'M')
1842 return (size_t) val;
1845 // Set the initial heap size. This might be ignored by the GC layer.
1846 // This must be called before _Jv_RunMain.
1848 _Jv_SetInitialHeapSize (const char *arg)
1850 size_t size = parse_memory_size (arg);
1851 _Jv_GCSetInitialHeapSize (size);
1854 // Set the maximum heap size. This might be ignored by the GC layer.
1855 // This must be called before _Jv_RunMain.
1857 _Jv_SetMaximumHeapSize (const char *arg)
1859 size_t size = parse_memory_size (arg);
1860 _Jv_GCSetMaximumHeapSize (size);
1864 _Jv_SetStackSize (const char *arg)
1866 size_t size = parse_memory_size (arg);
1867 gcj::stack_size = size;
1871 _Jv_Malloc (jsize size)
1873 if (__builtin_expect (size == 0, false))
1875 void *ptr = malloc ((size_t) size);
1876 if (__builtin_expect (ptr == NULL, false))
1882 _Jv_Realloc (void *ptr, jsize size)
1884 if (__builtin_expect (size == 0, false))
1886 ptr = realloc (ptr, (size_t) size);
1887 if (__builtin_expect (ptr == NULL, false))
1893 _Jv_MallocUnchecked (jsize size)
1895 if (__builtin_expect (size == 0, false))
1897 return malloc ((size_t) size);
1901 _Jv_Free (void* ptr)
1908 // In theory, these routines can be #ifdef'd away on machines which
1909 // support divide overflow signals. However, we never know if some
1910 // code might have been compiled with "-fuse-divide-subroutine", so we
1911 // always include them in libgcj.
1914 _Jv_divI (jint dividend, jint divisor)
1916 if (__builtin_expect (divisor == 0, false))
1918 java::lang::ArithmeticException *arithexception
1919 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1920 throw arithexception;
1923 if (dividend == (jint) 0x80000000L && divisor == -1)
1926 return dividend / divisor;
1930 _Jv_remI (jint dividend, jint divisor)
1932 if (__builtin_expect (divisor == 0, false))
1934 java::lang::ArithmeticException *arithexception
1935 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1936 throw arithexception;
1939 if (dividend == (jint) 0x80000000L && divisor == -1)
1942 return dividend % divisor;
1946 _Jv_divJ (jlong dividend, jlong divisor)
1948 if (__builtin_expect (divisor == 0, false))
1950 java::lang::ArithmeticException *arithexception
1951 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1952 throw arithexception;
1955 if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
1958 return dividend / divisor;
1962 _Jv_remJ (jlong dividend, jlong divisor)
1964 if (__builtin_expect (divisor == 0, false))
1966 java::lang::ArithmeticException *arithexception
1967 = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
1968 throw arithexception;
1971 if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
1974 return dividend % divisor;
1979 // Return true if SELF_KLASS can access a field or method in
1980 // OTHER_KLASS. The field or method's access flags are specified in
1983 _Jv_CheckAccess (jclass self_klass, jclass other_klass, jint flags)
1985 using namespace java::lang::reflect;
1986 return ((self_klass == other_klass)
1987 || ((flags & Modifier::PUBLIC) != 0)
1988 || (((flags & Modifier::PROTECTED) != 0)
1989 && _Jv_IsAssignableFromSlow (self_klass, other_klass))
1990 || (((flags & Modifier::PRIVATE) == 0)
1991 && _Jv_ClassNameSamePackage (self_klass->name,
1992 other_klass->name)));
1995 // Prepend GCJ_VERSIONED_LIBDIR to a module search path stored in a C
1996 // char array, if the path is not already prefixed by
1997 // GCJ_VERSIONED_LIBDIR. Return a newly JvMalloc'd char buffer. The
1998 // result should be freed using JvFree.
2000 _Jv_PrependVersionedLibdir (char* libpath)
2004 if (libpath && libpath[0] != '\0')
2006 if (! strncmp (libpath,
2007 GCJ_VERSIONED_LIBDIR,
2008 sizeof (GCJ_VERSIONED_LIBDIR) - 1))
2010 // LD_LIBRARY_PATH is already prefixed with
2011 // GCJ_VERSIONED_LIBDIR.
2012 retval = (char*) _Jv_Malloc (strlen (libpath) + 1);
2013 strcpy (retval, libpath);
2017 // LD_LIBRARY_PATH is not prefixed with
2018 // GCJ_VERSIONED_LIBDIR.
2020 path_sep[0] = (char) _Jv_platform_path_separator;
2022 jsize total = ((sizeof (GCJ_VERSIONED_LIBDIR) - 1)
2023 + 1 /* path separator */ + strlen (libpath) + 1);
2024 retval = (char*) _Jv_Malloc (total);
2025 strcpy (retval, GCJ_VERSIONED_LIBDIR);
2026 strcat (retval, path_sep);
2027 strcat (retval, libpath);
2032 // LD_LIBRARY_PATH was not specified or is empty.
2033 retval = (char*) _Jv_Malloc (sizeof (GCJ_VERSIONED_LIBDIR));
2034 strcpy (retval, GCJ_VERSIONED_LIBDIR);