prims.cc 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039
  1. // prims.cc - Code for core of runtime environment.
  2. /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. #include <config.h>
  8. #include <platform.h>
  9. #include <stdlib.h>
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <signal.h>
  14. #ifdef HAVE_UNISTD_H
  15. #include <unistd.h>
  16. #endif
  17. #include <gcj/cni.h>
  18. #include <jvm.h>
  19. #include <java-signal.h>
  20. #include <java-threads.h>
  21. #include <java-interp.h>
  22. #ifdef ENABLE_JVMPI
  23. #include <jvmpi.h>
  24. #include <java/lang/ThreadGroup.h>
  25. #endif
  26. #ifdef INTERPRETER
  27. #include <jvmti.h>
  28. #include "jvmti-int.h"
  29. #endif
  30. #ifndef DISABLE_GETENV_PROPERTIES
  31. #include <java-props.h>
  32. #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
  33. #else
  34. #define PROCESS_GCJ_PROPERTIES
  35. #endif // DISABLE_GETENV_PROPERTIES
  36. #include <java/lang/Class.h>
  37. #include <java/lang/ClassLoader.h>
  38. #include <java/lang/Runtime.h>
  39. #include <java/lang/String.h>
  40. #include <java/lang/Thread.h>
  41. #include <java/lang/ThreadGroup.h>
  42. #include <java/lang/ArrayIndexOutOfBoundsException.h>
  43. #include <java/lang/ArithmeticException.h>
  44. #include <java/lang/ClassFormatError.h>
  45. #include <java/lang/ClassNotFoundException.h>
  46. #include <java/lang/InternalError.h>
  47. #include <java/lang/NegativeArraySizeException.h>
  48. #include <java/lang/NoClassDefFoundError.h>
  49. #include <java/lang/NullPointerException.h>
  50. #include <java/lang/OutOfMemoryError.h>
  51. #include <java/lang/System.h>
  52. #include <java/lang/VMClassLoader.h>
  53. #include <java/lang/reflect/Modifier.h>
  54. #include <java/io/PrintStream.h>
  55. #include <java/lang/UnsatisfiedLinkError.h>
  56. #include <java/lang/VirtualMachineError.h>
  57. #include <gnu/gcj/runtime/ExtensionClassLoader.h>
  58. #include <gnu/gcj/runtime/FinalizerThread.h>
  59. #include <execution.h>
  60. #ifdef INTERPRETER
  61. #include <gnu/classpath/jdwp/Jdwp.h>
  62. #include <gnu/classpath/jdwp/VMVirtualMachine.h>
  63. #endif // INTERPRETER
  64. #include <gnu/java/lang/MainThread.h>
  65. #ifdef USE_LTDL
  66. #include <ltdl.h>
  67. #endif
  68. // Execution engine for compiled code.
  69. _Jv_CompiledEngine _Jv_soleCompiledEngine;
  70. // Execution engine for code compiled with -findirect-classes
  71. _Jv_IndirectCompiledEngine _Jv_soleIndirectCompiledEngine;
  72. // We allocate a single OutOfMemoryError exception which we keep
  73. // around for use if we run out of memory.
  74. static java::lang::OutOfMemoryError *no_memory;
  75. // Number of bytes in largest array object we create. This could be
  76. // increased to the largest size_t value, so long as the appropriate
  77. // functions are changed to take a size_t argument instead of jint.
  78. #define MAX_OBJECT_SIZE (((size_t)1<<31) - 1)
  79. // Properties set at compile time.
  80. const char **_Jv_Compiler_Properties = NULL;
  81. int _Jv_Properties_Count = 0;
  82. #ifndef DISABLE_GETENV_PROPERTIES
  83. // Property key/value pairs.
  84. property_pair *_Jv_Environment_Properties;
  85. #endif
  86. // Stash the argv pointer to benefit native libraries that need it.
  87. const char **_Jv_argv;
  88. int _Jv_argc;
  89. // Debugging options
  90. static bool remoteDebug = false;
  91. #ifdef INTERPRETER
  92. static char defaultJdwpOptions[] = "";
  93. static char *jdwpOptions = defaultJdwpOptions;
  94. // Typedefs for JVMTI agent functions.
  95. typedef jint jvmti_agent_onload_func (JavaVM *vm, char *options,
  96. void *reserved);
  97. typedef jint jvmti_agent_onunload_func (JavaVM *vm);
  98. // JVMTI agent function pointers.
  99. static jvmti_agent_onload_func *jvmti_agentonload = NULL;
  100. static jvmti_agent_onunload_func *jvmti_agentonunload = NULL;
  101. static char *jvmti_agent_opts;
  102. #endif // INTERPRETER
  103. // Argument support.
  104. int
  105. _Jv_GetNbArgs (void)
  106. {
  107. // _Jv_argc is 0 if not explicitly initialized.
  108. return _Jv_argc;
  109. }
  110. const char *
  111. _Jv_GetSafeArg (int index)
  112. {
  113. if (index >=0 && index < _Jv_GetNbArgs ())
  114. return _Jv_argv[index];
  115. else
  116. return "";
  117. }
  118. void
  119. _Jv_SetArgs (int argc, const char **argv)
  120. {
  121. _Jv_argc = argc;
  122. _Jv_argv = argv;
  123. }
  124. #ifdef ENABLE_JVMPI
  125. // Pointer to JVMPI notification functions.
  126. void (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (JVMPI_Event *event);
  127. void (*_Jv_JVMPI_Notify_THREAD_START) (JVMPI_Event *event);
  128. void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
  129. #endif
  130. #if defined (HANDLE_SEGV) || defined(HANDLE_FPE)
  131. /* Unblock a signal. Unless we do this, the signal may only be sent
  132. once. */
  133. static void
  134. unblock_signal (int signum __attribute__ ((__unused__)))
  135. {
  136. #ifdef _POSIX_VERSION
  137. sigset_t sigs;
  138. sigemptyset (&sigs);
  139. sigaddset (&sigs, signum);
  140. sigprocmask (SIG_UNBLOCK, &sigs, NULL);
  141. #endif
  142. }
  143. #endif
  144. #ifdef HANDLE_SEGV
  145. SIGNAL_HANDLER (catch_segv)
  146. {
  147. unblock_signal (SIGSEGV);
  148. MAKE_THROW_FRAME (nullp);
  149. java::lang::NullPointerException *nullp
  150. = new java::lang::NullPointerException;
  151. throw nullp;
  152. }
  153. #endif
  154. #ifdef HANDLE_FPE
  155. SIGNAL_HANDLER (catch_fpe)
  156. {
  157. unblock_signal (SIGFPE);
  158. #ifdef HANDLE_DIVIDE_OVERFLOW
  159. HANDLE_DIVIDE_OVERFLOW;
  160. #else
  161. MAKE_THROW_FRAME (arithexception);
  162. #endif
  163. java::lang::ArithmeticException *arithexception
  164. = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
  165. throw arithexception;
  166. }
  167. #endif
  168. jboolean
  169. _Jv_equalUtf8Consts (const Utf8Const* a, const Utf8Const *b)
  170. {
  171. int len;
  172. const _Jv_ushort *aptr, *bptr;
  173. if (a == b)
  174. return true;
  175. if (a->hash != b->hash)
  176. return false;
  177. len = a->length;
  178. if (b->length != len)
  179. return false;
  180. aptr = (const _Jv_ushort *)a->data;
  181. bptr = (const _Jv_ushort *)b->data;
  182. len = (len + 1) >> 1;
  183. while (--len >= 0)
  184. if (*aptr++ != *bptr++)
  185. return false;
  186. return true;
  187. }
  188. /* True iff A is equal to STR.
  189. HASH is STR->hashCode().
  190. */
  191. jboolean
  192. _Jv_equal (Utf8Const* a, jstring str, jint hash)
  193. {
  194. if (a->hash != (_Jv_ushort) hash)
  195. return false;
  196. jint len = str->length();
  197. jint i = 0;
  198. jchar *sptr = _Jv_GetStringChars (str);
  199. unsigned char* ptr = (unsigned char*) a->data;
  200. unsigned char* limit = ptr + a->length;
  201. for (;; i++, sptr++)
  202. {
  203. int ch = UTF8_GET (ptr, limit);
  204. if (i == len)
  205. return ch < 0;
  206. if (ch != *sptr)
  207. return false;
  208. }
  209. return true;
  210. }
  211. /* Like _Jv_equal, but stop after N characters. */
  212. jboolean
  213. _Jv_equaln (Utf8Const *a, jstring str, jint n)
  214. {
  215. jint len = str->length();
  216. jint i = 0;
  217. jchar *sptr = _Jv_GetStringChars (str);
  218. unsigned char* ptr = (unsigned char*) a->data;
  219. unsigned char* limit = ptr + a->length;
  220. for (; n-- > 0; i++, sptr++)
  221. {
  222. int ch = UTF8_GET (ptr, limit);
  223. if (i == len)
  224. return ch < 0;
  225. if (ch != *sptr)
  226. return false;
  227. }
  228. return true;
  229. }
  230. // Determines whether the given Utf8Const object contains
  231. // a type which is primitive or some derived form of it, eg.
  232. // an array or multi-dimensional array variant.
  233. jboolean
  234. _Jv_isPrimitiveOrDerived(const Utf8Const *a)
  235. {
  236. unsigned char *aptr = (unsigned char *) a->data;
  237. unsigned char *alimit = aptr + a->length;
  238. int ac = UTF8_GET(aptr, alimit);
  239. // Skips any leading array marks.
  240. while (ac == '[')
  241. ac = UTF8_GET(aptr, alimit);
  242. // There should not be another character. This implies that
  243. // the type name is only one character long.
  244. if (UTF8_GET(aptr, alimit) == -1)
  245. switch ( ac )
  246. {
  247. case 'Z':
  248. case 'B':
  249. case 'C':
  250. case 'S':
  251. case 'I':
  252. case 'J':
  253. case 'F':
  254. case 'D':
  255. return true;
  256. default:
  257. break;
  258. }
  259. return false;
  260. }
  261. // Find out whether two _Jv_Utf8Const candidates contain the same
  262. // classname.
  263. // The method is written to handle the different formats of classnames.
  264. // Eg. "Ljava/lang/Class;", "Ljava.lang.Class;", "java/lang/Class" and
  265. // "java.lang.Class" will be seen as equal.
  266. // Warning: This function is not smart enough to declare "Z" and "boolean"
  267. // and similar cases as equal (and is not meant to be used this way)!
  268. jboolean
  269. _Jv_equalUtf8Classnames (const Utf8Const *a, const Utf8Const *b)
  270. {
  271. // If the class name's length differs by two characters
  272. // it is possible that we have candidates which are given
  273. // in the two different formats ("Lp1/p2/cn;" vs. "p1/p2/cn")
  274. switch (a->length - b->length)
  275. {
  276. case -2:
  277. case 0:
  278. case 2:
  279. break;
  280. default:
  281. return false;
  282. }
  283. unsigned char *aptr = (unsigned char *) a->data;
  284. unsigned char *alimit = aptr + a->length;
  285. unsigned char *bptr = (unsigned char *) b->data;
  286. unsigned char *blimit = bptr + b->length;
  287. if (alimit[-1] == ';')
  288. alimit--;
  289. if (blimit[-1] == ';')
  290. blimit--;
  291. int ac = UTF8_GET(aptr, alimit);
  292. int bc = UTF8_GET(bptr, blimit);
  293. // Checks whether both strings have the same amount of leading [ characters.
  294. while (ac == '[')
  295. {
  296. if (bc == '[')
  297. {
  298. ac = UTF8_GET(aptr, alimit);
  299. bc = UTF8_GET(bptr, blimit);
  300. continue;
  301. }
  302. return false;
  303. }
  304. // Skips leading L character.
  305. if (ac == 'L')
  306. ac = UTF8_GET(aptr, alimit);
  307. if (bc == 'L')
  308. bc = UTF8_GET(bptr, blimit);
  309. // Compares the remaining characters.
  310. while (ac != -1 && bc != -1)
  311. {
  312. // Replaces package separating dots with slashes.
  313. if (ac == '.')
  314. ac = '/';
  315. if (bc == '.')
  316. bc = '/';
  317. // Now classnames differ if there is at least one non-matching
  318. // character.
  319. if (ac != bc)
  320. return false;
  321. ac = UTF8_GET(aptr, alimit);
  322. bc = UTF8_GET(bptr, blimit);
  323. }
  324. return (ac == bc);
  325. }
  326. /* Count the number of Unicode chars encoded in a given Ut8 string. */
  327. int
  328. _Jv_strLengthUtf8(const char* str, int len)
  329. {
  330. unsigned char* ptr;
  331. unsigned char* limit;
  332. int str_length;
  333. ptr = (unsigned char*) str;
  334. limit = ptr + len;
  335. str_length = 0;
  336. for (; ptr < limit; str_length++)
  337. {
  338. if (UTF8_GET (ptr, limit) < 0)
  339. return (-1);
  340. }
  341. return (str_length);
  342. }
  343. /* Calculate a hash value for a string encoded in Utf8 format.
  344. * This returns the same hash value as specified or java.lang.String.hashCode.
  345. */
  346. jint
  347. _Jv_hashUtf8String (const char* str, int len)
  348. {
  349. unsigned char* ptr = (unsigned char*) str;
  350. unsigned char* limit = ptr + len;
  351. jint hash = 0;
  352. for (; ptr < limit;)
  353. {
  354. int ch = UTF8_GET (ptr, limit);
  355. /* Updated specification from
  356. http://www.javasoft.com/docs/books/jls/clarify.html. */
  357. hash = (31 * hash) + ch;
  358. }
  359. return hash;
  360. }
  361. void
  362. _Jv_Utf8Const::init(const char *s, int len)
  363. {
  364. ::memcpy (data, s, len);
  365. data[len] = 0;
  366. length = len;
  367. hash = _Jv_hashUtf8String (s, len) & 0xFFFF;
  368. }
  369. _Jv_Utf8Const *
  370. _Jv_makeUtf8Const (const char* s, int len)
  371. {
  372. if (len < 0)
  373. len = strlen (s);
  374. Utf8Const* m
  375. = (Utf8Const*) _Jv_AllocBytes (_Jv_Utf8Const::space_needed(s, len));
  376. m->init(s, len);
  377. return m;
  378. }
  379. _Jv_Utf8Const *
  380. _Jv_makeUtf8Const (jstring string)
  381. {
  382. jint hash = string->hashCode ();
  383. jint len = _Jv_GetStringUTFLength (string);
  384. Utf8Const* m = (Utf8Const*)
  385. _Jv_AllocBytes (sizeof(Utf8Const) + len + 1);
  386. m->hash = hash;
  387. m->length = len;
  388. _Jv_GetStringUTFRegion (string, 0, string->length (), m->data);
  389. m->data[len] = 0;
  390. return m;
  391. }
  392. #ifdef __GCJ_DEBUG
  393. void
  394. _Jv_Abort (const char *function, const char *file, int line,
  395. const char *message)
  396. #else
  397. void
  398. _Jv_Abort (const char *, const char *, int, const char *message)
  399. #endif
  400. {
  401. #ifdef __GCJ_DEBUG
  402. fprintf (stderr,
  403. "libgcj failure: %s\n in function %s, file %s, line %d\n",
  404. message, function, file, line);
  405. #else
  406. fprintf (stderr, "libgcj failure: %s\n", message);
  407. #endif
  408. fflush (stderr);
  409. abort ();
  410. }
  411. static void
  412. fail_on_finalization (jobject)
  413. {
  414. JvFail ("object was finalized");
  415. }
  416. void
  417. _Jv_GCWatch (jobject obj)
  418. {
  419. _Jv_RegisterFinalizer (obj, fail_on_finalization);
  420. }
  421. void
  422. _Jv_ThrowBadArrayIndex(jint bad_index)
  423. {
  424. throw new java::lang::ArrayIndexOutOfBoundsException
  425. (java::lang::String::valueOf (bad_index));
  426. }
  427. void
  428. _Jv_ThrowNullPointerException ()
  429. {
  430. throw new java::lang::NullPointerException;
  431. }
  432. // Resolve an entry in the constant pool and return the target
  433. // address.
  434. void *
  435. _Jv_ResolvePoolEntry (jclass this_class, jint index)
  436. {
  437. _Jv_Constants *pool = &this_class->constants;
  438. if ((pool->tags[index] & JV_CONSTANT_ResolvedFlag) != 0)
  439. return pool->data[index].field->u.addr;
  440. JvSynchronize sync (this_class);
  441. return (_Jv_Linker::resolve_pool_entry (this_class, index))
  442. .field->u.addr;
  443. }
  444. // Explicitly throw a no memory exception.
  445. // The collector calls this when it encounters an out-of-memory condition.
  446. void _Jv_ThrowNoMemory()
  447. {
  448. throw no_memory;
  449. }
  450. #ifdef ENABLE_JVMPI
  451. # define JVMPI_NOTIFY_ALLOC(klass,size,obj) \
  452. if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false)) \
  453. jvmpi_notify_alloc(klass,size,obj);
  454. static void
  455. jvmpi_notify_alloc(jclass klass, jint size, jobject obj)
  456. {
  457. // Service JVMPI allocation request.
  458. JVMPI_Event event;
  459. event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
  460. event.env_id = NULL;
  461. event.u.obj_alloc.arena_id = 0;
  462. event.u.obj_alloc.class_id = (jobjectID) klass;
  463. event.u.obj_alloc.is_array = 0;
  464. event.u.obj_alloc.size = size;
  465. event.u.obj_alloc.obj_id = (jobjectID) obj;
  466. // FIXME: This doesn't look right for the Boehm GC. A GC may
  467. // already be in progress. _Jv_DisableGC () doesn't wait for it.
  468. // More importantly, I don't see the need for disabling GC, since we
  469. // blatantly have a pointer to obj on our stack, ensuring that the
  470. // object can't be collected. Even for a nonconservative collector,
  471. // it appears to me that this must be true, since we are about to
  472. // return obj. Isn't this whole approach way too intrusive for
  473. // a useful profiling interface? - HB
  474. _Jv_DisableGC ();
  475. (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
  476. _Jv_EnableGC ();
  477. }
  478. #else /* !ENABLE_JVMPI */
  479. # define JVMPI_NOTIFY_ALLOC(klass,size,obj) /* do nothing */
  480. #endif
  481. // Allocate a new object of class KLASS.
  482. // First a version that assumes that we have no finalizer, and that
  483. // the class is already initialized.
  484. // If we know that JVMPI is disabled, this can be replaced by a direct call
  485. // to the allocator for the appropriate GC.
  486. jobject
  487. _Jv_AllocObjectNoInitNoFinalizer (jclass klass)
  488. {
  489. jint size = klass->size ();
  490. jobject obj = (jobject) _Jv_AllocObj (size, klass);
  491. JVMPI_NOTIFY_ALLOC (klass, size, obj);
  492. return obj;
  493. }
  494. // And now a version that initializes if necessary.
  495. jobject
  496. _Jv_AllocObjectNoFinalizer (jclass klass)
  497. {
  498. if (_Jv_IsPhantomClass(klass) )
  499. throw new java::lang::NoClassDefFoundError(klass->getName());
  500. _Jv_InitClass (klass);
  501. jint size = klass->size ();
  502. jobject obj = (jobject) _Jv_AllocObj (size, klass);
  503. JVMPI_NOTIFY_ALLOC (klass, size, obj);
  504. return obj;
  505. }
  506. // And now the general version that registers a finalizer if necessary.
  507. jobject
  508. _Jv_AllocObject (jclass klass)
  509. {
  510. jobject obj = _Jv_AllocObjectNoFinalizer (klass);
  511. // We assume that the compiler only generates calls to this routine
  512. // if there really is an interesting finalizer.
  513. // Unfortunately, we still have to the dynamic test, since there may
  514. // be cni calls to this routine.
  515. // Note that on IA64 get_finalizer() returns the starting address of the
  516. // function, not a function pointer. Thus this still works.
  517. if (klass->vtable->get_finalizer ()
  518. != java::lang::Object::class$.vtable->get_finalizer ())
  519. _Jv_RegisterFinalizer (obj, _Jv_FinalizeObject);
  520. return obj;
  521. }
  522. // Allocate a String, including variable length storage.
  523. jstring
  524. _Jv_AllocString(jsize len)
  525. {
  526. using namespace java::lang;
  527. jsize sz = sizeof(java::lang::String) + len * sizeof(jchar);
  528. // We assert that for strings allocated this way, the data field
  529. // will always point to the object itself. Thus there is no reason
  530. // for the garbage collector to scan any of it.
  531. // Furthermore, we're about to overwrite the string data, so
  532. // initialization of the object is not an issue.
  533. // String needs no initialization, and there is no finalizer, so
  534. // we can go directly to the collector's allocator interface.
  535. jstring obj = (jstring) _Jv_AllocPtrFreeObj(sz, &String::class$);
  536. obj->data = obj;
  537. obj->boffset = sizeof(java::lang::String);
  538. obj->count = len;
  539. obj->cachedHashCode = 0;
  540. JVMPI_NOTIFY_ALLOC (&String::class$, sz, obj);
  541. return obj;
  542. }
  543. // A version of the above that assumes the object contains no pointers,
  544. // and requires no finalization. This can't happen if we need pointers
  545. // to locks.
  546. #ifdef JV_HASH_SYNCHRONIZATION
  547. jobject
  548. _Jv_AllocPtrFreeObject (jclass klass)
  549. {
  550. _Jv_InitClass (klass);
  551. jint size = klass->size ();
  552. jobject obj = (jobject) _Jv_AllocPtrFreeObj (size, klass);
  553. JVMPI_NOTIFY_ALLOC (klass, size, obj);
  554. return obj;
  555. }
  556. #endif /* JV_HASH_SYNCHRONIZATION */
  557. // Allocate a new array of Java objects. Each object is of type
  558. // `elementClass'. `init' is used to initialize each slot in the
  559. // array.
  560. jobjectArray
  561. _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
  562. {
  563. // Creating an array of an unresolved type is impossible. So we throw
  564. // the NoClassDefFoundError.
  565. if ( _Jv_IsPhantomClass(elementClass) )
  566. throw new java::lang::NoClassDefFoundError(elementClass->getName());
  567. if (__builtin_expect (count < 0, false))
  568. throw new java::lang::NegativeArraySizeException;
  569. JvAssert (! elementClass->isPrimitive ());
  570. // Ensure that elements pointer is properly aligned.
  571. jobjectArray obj = NULL;
  572. size_t size = (size_t) elements (obj);
  573. // Check for overflow.
  574. if (__builtin_expect ((size_t) count >
  575. (MAX_OBJECT_SIZE - 1 - size) / sizeof (jobject), false))
  576. throw no_memory;
  577. size += count * sizeof (jobject);
  578. jclass klass = _Jv_GetArrayClass (elementClass,
  579. elementClass->getClassLoaderInternal());
  580. obj = (jobjectArray) _Jv_AllocArray (size, klass);
  581. // Cast away const.
  582. jsize *lp = const_cast<jsize *> (&obj->length);
  583. *lp = count;
  584. // We know the allocator returns zeroed memory. So don't bother
  585. // zeroing it again.
  586. if (init)
  587. {
  588. jobject *ptr = elements(obj);
  589. while (--count >= 0)
  590. *ptr++ = init;
  591. }
  592. return obj;
  593. }
  594. // Allocate a new array of primitives. ELTYPE is the type of the
  595. // element, COUNT is the size of the array.
  596. jobject
  597. _Jv_NewPrimArray (jclass eltype, jint count)
  598. {
  599. int elsize = eltype->size();
  600. if (__builtin_expect (count < 0, false))
  601. throw new java::lang::NegativeArraySizeException;
  602. JvAssert (eltype->isPrimitive ());
  603. jobject dummy = NULL;
  604. size_t size = (size_t) _Jv_GetArrayElementFromElementType (dummy, eltype);
  605. // Check for overflow.
  606. if (__builtin_expect ((size_t) count >
  607. (MAX_OBJECT_SIZE - size) / elsize, false))
  608. throw no_memory;
  609. jclass klass = _Jv_GetArrayClass (eltype, 0);
  610. # ifdef JV_HASH_SYNCHRONIZATION
  611. // Since the vtable is always statically allocated,
  612. // these are completely pointerfree! Make sure the GC doesn't touch them.
  613. __JArray *arr =
  614. (__JArray*) _Jv_AllocPtrFreeObj (size + elsize * count, klass);
  615. memset((char *)arr + size, 0, elsize * count);
  616. # else
  617. __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass);
  618. // Note that we assume we are given zeroed memory by the allocator.
  619. # endif
  620. // Cast away const.
  621. jsize *lp = const_cast<jsize *> (&arr->length);
  622. *lp = count;
  623. return arr;
  624. }
  625. jobject
  626. _Jv_NewArray (jint type, jint size)
  627. {
  628. switch (type)
  629. {
  630. case 4: return JvNewBooleanArray (size);
  631. case 5: return JvNewCharArray (size);
  632. case 6: return JvNewFloatArray (size);
  633. case 7: return JvNewDoubleArray (size);
  634. case 8: return JvNewByteArray (size);
  635. case 9: return JvNewShortArray (size);
  636. case 10: return JvNewIntArray (size);
  637. case 11: return JvNewLongArray (size);
  638. }
  639. throw new java::lang::InternalError
  640. (JvNewStringLatin1 ("invalid type code in _Jv_NewArray"));
  641. }
  642. // Allocate a possibly multi-dimensional array but don't check that
  643. // any array length is <0.
  644. static jobject
  645. _Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
  646. {
  647. JvAssert (type->isArray());
  648. jclass element_type = type->getComponentType();
  649. jobject result;
  650. if (element_type->isPrimitive())
  651. result = _Jv_NewPrimArray (element_type, sizes[0]);
  652. else
  653. result = _Jv_NewObjectArray (sizes[0], element_type, NULL);
  654. if (dimensions > 1)
  655. {
  656. JvAssert (! element_type->isPrimitive());
  657. JvAssert (element_type->isArray());
  658. jobject *contents = elements ((jobjectArray) result);
  659. for (int i = 0; i < sizes[0]; ++i)
  660. contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
  661. sizes + 1);
  662. }
  663. return result;
  664. }
  665. jobject
  666. _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
  667. {
  668. for (int i = 0; i < dimensions; ++i)
  669. if (sizes[i] < 0)
  670. throw new java::lang::NegativeArraySizeException;
  671. return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
  672. }
  673. jobject
  674. _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
  675. {
  676. // Creating an array of an unresolved type is impossible. So we throw
  677. // the NoClassDefFoundError.
  678. if (_Jv_IsPhantomClass(array_type))
  679. throw new java::lang::NoClassDefFoundError(array_type->getName());
  680. va_list args;
  681. jint sizes[dimensions];
  682. va_start (args, dimensions);
  683. for (int i = 0; i < dimensions; ++i)
  684. {
  685. jint size = va_arg (args, jint);
  686. if (size < 0)
  687. throw new java::lang::NegativeArraySizeException;
  688. sizes[i] = size;
  689. }
  690. va_end (args);
  691. return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
  692. }
  693. // Ensure 8-byte alignment, for hash synchronization.
  694. #define DECLARE_PRIM_TYPE(NAME) \
  695. java::lang::Class _Jv_##NAME##Class __attribute__ ((aligned (8)));
  696. DECLARE_PRIM_TYPE(byte)
  697. DECLARE_PRIM_TYPE(short)
  698. DECLARE_PRIM_TYPE(int)
  699. DECLARE_PRIM_TYPE(long)
  700. DECLARE_PRIM_TYPE(boolean)
  701. DECLARE_PRIM_TYPE(char)
  702. DECLARE_PRIM_TYPE(float)
  703. DECLARE_PRIM_TYPE(double)
  704. DECLARE_PRIM_TYPE(void)
  705. void
  706. _Jv_InitPrimClass (jclass cl, const char *cname, char sig, int len)
  707. {
  708. using namespace java::lang::reflect;
  709. // We must set the vtable for the class; the Java constructor
  710. // doesn't do this.
  711. (*(_Jv_VTable **) cl) = java::lang::Class::class$.vtable;
  712. // Initialize the fields we care about. We do this in the same
  713. // order they are declared in Class.h.
  714. cl->name = _Jv_makeUtf8Const ((char *) cname, -1);
  715. cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT;
  716. cl->method_count = sig;
  717. cl->size_in_bytes = len;
  718. cl->vtable = JV_PRIMITIVE_VTABLE;
  719. cl->state = JV_STATE_DONE;
  720. cl->depth = -1;
  721. }
  722. jclass
  723. _Jv_FindClassFromSignature (char *sig, java::lang::ClassLoader *loader,
  724. char **endp)
  725. {
  726. // First count arrays.
  727. int array_count = 0;
  728. while (*sig == '[')
  729. {
  730. ++sig;
  731. ++array_count;
  732. }
  733. jclass result = NULL;
  734. switch (*sig)
  735. {
  736. case 'B':
  737. result = JvPrimClass (byte);
  738. break;
  739. case 'S':
  740. result = JvPrimClass (short);
  741. break;
  742. case 'I':
  743. result = JvPrimClass (int);
  744. break;
  745. case 'J':
  746. result = JvPrimClass (long);
  747. break;
  748. case 'Z':
  749. result = JvPrimClass (boolean);
  750. break;
  751. case 'C':
  752. result = JvPrimClass (char);
  753. break;
  754. case 'F':
  755. result = JvPrimClass (float);
  756. break;
  757. case 'D':
  758. result = JvPrimClass (double);
  759. break;
  760. case 'V':
  761. result = JvPrimClass (void);
  762. break;
  763. case 'L':
  764. {
  765. char *save = ++sig;
  766. while (*sig && *sig != ';')
  767. ++sig;
  768. // Do nothing if signature appears to be malformed.
  769. if (*sig == ';')
  770. {
  771. _Jv_Utf8Const *name = _Jv_makeUtf8Const (save, sig - save);
  772. result = _Jv_FindClass (name, loader);
  773. }
  774. break;
  775. }
  776. default:
  777. // Do nothing -- bad signature.
  778. break;
  779. }
  780. if (endp)
  781. {
  782. // Not really the "end", but the last valid character that we
  783. // looked at.
  784. *endp = sig;
  785. }
  786. if (! result)
  787. return NULL;
  788. // Find arrays.
  789. while (array_count-- > 0)
  790. result = _Jv_GetArrayClass (result, loader);
  791. return result;
  792. }
  793. jclass
  794. _Jv_FindClassFromSignatureNoException (char *sig, java::lang::ClassLoader *loader,
  795. char **endp)
  796. {
  797. jclass klass;
  798. try
  799. {
  800. klass = _Jv_FindClassFromSignature(sig, loader, endp);
  801. }
  802. catch (java::lang::NoClassDefFoundError *ncdfe)
  803. {
  804. return NULL;
  805. }
  806. catch (java::lang::ClassNotFoundException *cnfe)
  807. {
  808. return NULL;
  809. }
  810. return klass;
  811. }
  812. JArray<jstring> *
  813. JvConvertArgv (int argc, const char **argv)
  814. {
  815. if (argc < 0)
  816. argc = 0;
  817. jobjectArray ar = JvNewObjectArray(argc, &java::lang::String::class$, NULL);
  818. jobject *ptr = elements(ar);
  819. jbyteArray bytes = NULL;
  820. for (int i = 0; i < argc; i++)
  821. {
  822. const char *arg = argv[i];
  823. int len = strlen (arg);
  824. if (bytes == NULL || bytes->length < len)
  825. bytes = JvNewByteArray (len);
  826. jbyte *bytePtr = elements (bytes);
  827. // We assume jbyte == char.
  828. memcpy (bytePtr, arg, len);
  829. // Now convert using the default encoding.
  830. *ptr++ = new java::lang::String (bytes, 0, len);
  831. }
  832. return (JArray<jstring>*) ar;
  833. }
  834. // FIXME: These variables are static so that they will be
  835. // automatically scanned by the Boehm collector. This is needed
  836. // because with qthreads the collector won't scan the initial stack --
  837. // it will only scan the qthreads stacks.
  838. // Command line arguments.
  839. static JArray<jstring> *arg_vec;
  840. // The primary thread.
  841. static java::lang::Thread *main_thread;
  842. #ifndef DISABLE_GETENV_PROPERTIES
  843. #define c_isspace(c) (memchr (" \t\n\r\v\f", c, 6) != NULL)
  844. static char *
  845. next_property_key (char *s, size_t *length)
  846. {
  847. size_t l = 0;
  848. JvAssert (s);
  849. // Skip over whitespace
  850. while (c_isspace (*s))
  851. s++;
  852. // If we've reached the end, return NULL. Also return NULL if for
  853. // some reason we've come across a malformed property string.
  854. if (*s == 0
  855. || *s == ':'
  856. || *s == '=')
  857. return NULL;
  858. // Determine the length of the property key.
  859. while (s[l] != 0
  860. && ! c_isspace (s[l])
  861. && s[l] != ':'
  862. && s[l] != '=')
  863. {
  864. if (s[l] == '\\'
  865. && s[l+1] != 0)
  866. l++;
  867. l++;
  868. }
  869. *length = l;
  870. return s;
  871. }
  872. static char *
  873. next_property_value (char *s, size_t *length)
  874. {
  875. size_t l = 0;
  876. JvAssert (s);
  877. while (c_isspace (*s))
  878. s++;
  879. if (*s == ':'
  880. || *s == '=')
  881. s++;
  882. while (c_isspace (*s))
  883. s++;
  884. // Determine the length of the property value.
  885. while (s[l] != 0
  886. && ! c_isspace (s[l])
  887. && s[l] != ':'
  888. && s[l] != '=')
  889. {
  890. if (s[l] == '\\'
  891. && s[l+1] != 0)
  892. l += 2;
  893. else
  894. l++;
  895. }
  896. *length = l;
  897. return s;
  898. }
  899. static void
  900. process_gcj_properties ()
  901. {
  902. char *props = getenv("GCJ_PROPERTIES");
  903. if (NULL == props)
  904. return;
  905. // Later on we will write \0s into this string. It is simplest to
  906. // just duplicate it here.
  907. props = strdup (props);
  908. char *p = props;
  909. size_t length;
  910. size_t property_count = 0;
  911. // Whip through props quickly in order to count the number of
  912. // property values.
  913. while (p && (p = next_property_key (p, &length)))
  914. {
  915. // Skip to the end of the key
  916. p += length;
  917. p = next_property_value (p, &length);
  918. if (p)
  919. p += length;
  920. property_count++;
  921. }
  922. // Allocate an array of property value/key pairs.
  923. _Jv_Environment_Properties =
  924. (property_pair *) malloc (sizeof(property_pair)
  925. * (property_count + 1));
  926. // Go through the properties again, initializing _Jv_Properties
  927. // along the way.
  928. p = props;
  929. property_count = 0;
  930. while (p && (p = next_property_key (p, &length)))
  931. {
  932. _Jv_Environment_Properties[property_count].key = p;
  933. _Jv_Environment_Properties[property_count].key_length = length;
  934. // Skip to the end of the key
  935. p += length;
  936. p = next_property_value (p, &length);
  937. _Jv_Environment_Properties[property_count].value = p;
  938. _Jv_Environment_Properties[property_count].value_length = length;
  939. if (p)
  940. p += length;
  941. property_count++;
  942. }
  943. memset ((void *) &_Jv_Environment_Properties[property_count],
  944. 0, sizeof (property_pair));
  945. // Null terminate the strings.
  946. for (property_pair *prop = &_Jv_Environment_Properties[0];
  947. prop->key != NULL;
  948. prop++)
  949. {
  950. prop->key[prop->key_length] = 0;
  951. prop->value[prop->value_length] = 0;
  952. }
  953. }
  954. #endif // DISABLE_GETENV_PROPERTIES
  955. namespace gcj
  956. {
  957. _Jv_Utf8Const *void_signature;
  958. _Jv_Utf8Const *clinit_name;
  959. _Jv_Utf8Const *init_name;
  960. _Jv_Utf8Const *finit_name;
  961. bool runtimeInitialized = false;
  962. // When true, print debugging information about class loading.
  963. bool verbose_class_flag;
  964. // When true, enable the bytecode verifier and BC-ABI type verification.
  965. bool verifyClasses = true;
  966. // Thread stack size specified by the -Xss runtime argument.
  967. size_t stack_size = 0;
  968. // Start time of the VM
  969. jlong startTime = 0;
  970. // Arguments passed to the VM
  971. JArray<jstring>* vmArgs;
  972. // Currently loaded classes
  973. jint loadedClasses = 0;
  974. // Unloaded classes
  975. jlong unloadedClasses = 0;
  976. }
  977. // We accept all non-standard options accepted by Sun's java command,
  978. // for compatibility with existing application launch scripts.
  979. static jint
  980. parse_x_arg (char* option_string)
  981. {
  982. if (strlen (option_string) <= 0)
  983. return -1;
  984. if (! strcmp (option_string, "int"))
  985. {
  986. // FIXME: this should cause the vm to never load shared objects
  987. }
  988. else if (! strcmp (option_string, "mixed"))
  989. {
  990. // FIXME: allow interpreted and native code
  991. }
  992. else if (! strcmp (option_string, "batch"))
  993. {
  994. // FIXME: disable background JIT'ing
  995. }
  996. else if (! strcmp (option_string, "debug"))
  997. {
  998. remoteDebug = true;
  999. }
  1000. #ifdef INTERPRETER
  1001. else if (! strncmp (option_string, "runjdwp:", 8))
  1002. {
  1003. if (strlen (option_string) > 8)
  1004. jdwpOptions = &option_string[8];
  1005. else
  1006. {
  1007. fprintf (stderr,
  1008. "libgcj: argument required for JDWP options");
  1009. return -1;
  1010. }
  1011. }
  1012. #endif // INTERPRETER
  1013. else if (! strncmp (option_string, "bootclasspath:", 14))
  1014. {
  1015. // FIXME: add a parse_bootclasspath_arg function
  1016. }
  1017. else if (! strncmp (option_string, "bootclasspath/a:", 16))
  1018. {
  1019. }
  1020. else if (! strncmp (option_string, "bootclasspath/p:", 16))
  1021. {
  1022. }
  1023. else if (! strcmp (option_string, "check:jni"))
  1024. {
  1025. // FIXME: enable strict JNI checking
  1026. }
  1027. else if (! strcmp (option_string, "future"))
  1028. {
  1029. // FIXME: enable strict class file format checks
  1030. }
  1031. else if (! strcmp (option_string, "noclassgc"))
  1032. {
  1033. // FIXME: disable garbage collection for classes
  1034. }
  1035. else if (! strcmp (option_string, "incgc"))
  1036. {
  1037. // FIXME: incremental garbage collection
  1038. }
  1039. else if (! strncmp (option_string, "loggc:", 6))
  1040. {
  1041. if (option_string[6] == '\0')
  1042. {
  1043. fprintf (stderr,
  1044. "libgcj: filename argument expected for loggc option\n");
  1045. return -1;
  1046. }
  1047. // FIXME: set gc logging filename
  1048. }
  1049. else if (! strncmp (option_string, "ms", 2))
  1050. {
  1051. // FIXME: ignore this option until PR 20699 is fixed.
  1052. // _Jv_SetInitialHeapSize (option_string + 2);
  1053. }
  1054. else if (! strncmp (option_string, "mx", 2))
  1055. _Jv_SetMaximumHeapSize (option_string + 2);
  1056. else if (! strcmp (option_string, "prof"))
  1057. {
  1058. // FIXME: enable profiling of program running in vm
  1059. }
  1060. else if (! strncmp (option_string, "runhprof:", 9))
  1061. {
  1062. // FIXME: enable specific type of vm profiling. add a
  1063. // parse_runhprof_arg function
  1064. }
  1065. else if (! strcmp (option_string, "rs"))
  1066. {
  1067. // FIXME: reduced system signal usage. disable thread dumps,
  1068. // only terminate in response to user-initiated calls,
  1069. // e.g. System.exit()
  1070. }
  1071. else if (! strncmp (option_string, "ss", 2))
  1072. {
  1073. _Jv_SetStackSize (option_string + 2);
  1074. }
  1075. else if (! strcmp (option_string, "X:+UseAltSigs"))
  1076. {
  1077. // FIXME: use signals other than SIGUSR1 and SIGUSR2
  1078. }
  1079. else if (! strcmp (option_string, "share:off"))
  1080. {
  1081. // FIXME: don't share class data
  1082. }
  1083. else if (! strcmp (option_string, "share:auto"))
  1084. {
  1085. // FIXME: share class data where possible
  1086. }
  1087. else if (! strcmp (option_string, "share:on"))
  1088. {
  1089. // FIXME: fail if impossible to share class data
  1090. }
  1091. else
  1092. {
  1093. // Unrecognized.
  1094. return -1;
  1095. }
  1096. return 0;
  1097. }
  1098. static jint
  1099. parse_verbose_args (char* option_string,
  1100. bool ignore_unrecognized)
  1101. {
  1102. size_t len = sizeof ("-verbose") - 1;
  1103. if (strlen (option_string) < len)
  1104. return -1;
  1105. if (option_string[len] == ':'
  1106. && option_string[len + 1] != '\0')
  1107. {
  1108. char* verbose_args = option_string + len + 1;
  1109. do
  1110. {
  1111. if (! strncmp (verbose_args,
  1112. "gc", sizeof ("gc") - 1))
  1113. {
  1114. if (verbose_args[sizeof ("gc") - 1] == '\0'
  1115. || verbose_args[sizeof ("gc") - 1] == ',')
  1116. {
  1117. // FIXME: we should add functions to boehm-gc that
  1118. // toggle GC_print_stats, GC_PRINT_ADDRESS_MAP and
  1119. // GC_print_back_height.
  1120. verbose_args += sizeof ("gc") - 1;
  1121. }
  1122. else
  1123. {
  1124. verbose_arg_err:
  1125. fprintf (stderr, "libgcj: unknown verbose option: %s\n",
  1126. option_string);
  1127. return -1;
  1128. }
  1129. }
  1130. else if (! strncmp (verbose_args,
  1131. "class",
  1132. sizeof ("class") - 1))
  1133. {
  1134. if (verbose_args[sizeof ("class") - 1] == '\0'
  1135. || verbose_args[sizeof ("class") - 1] == ',')
  1136. {
  1137. gcj::verbose_class_flag = true;
  1138. verbose_args += sizeof ("class") - 1;
  1139. }
  1140. else
  1141. goto verbose_arg_err;
  1142. }
  1143. else if (! strncmp (verbose_args, "jni",
  1144. sizeof ("jni") - 1))
  1145. {
  1146. if (verbose_args[sizeof ("jni") - 1] == '\0'
  1147. || verbose_args[sizeof ("jni") - 1] == ',')
  1148. {
  1149. // FIXME: enable JNI messages.
  1150. verbose_args += sizeof ("jni") - 1;
  1151. }
  1152. else
  1153. goto verbose_arg_err;
  1154. }
  1155. else if (ignore_unrecognized
  1156. && verbose_args[0] == 'X')
  1157. {
  1158. // ignore unrecognized non-standard verbose option
  1159. while (verbose_args[0] != '\0'
  1160. && verbose_args[0] != ',')
  1161. verbose_args++;
  1162. }
  1163. else if (verbose_args[0] == ',')
  1164. {
  1165. verbose_args++;
  1166. }
  1167. else
  1168. goto verbose_arg_err;
  1169. if (verbose_args[0] == ',')
  1170. verbose_args++;
  1171. }
  1172. while (verbose_args[0] != '\0');
  1173. }
  1174. else if (option_string[len] == 'g'
  1175. && option_string[len + 1] == 'c'
  1176. && option_string[len + 2] == '\0')
  1177. {
  1178. // FIXME: we should add functions to boehm-gc that
  1179. // toggle GC_print_stats, GC_PRINT_ADDRESS_MAP and
  1180. // GC_print_back_height.
  1181. return 0;
  1182. }
  1183. else if (option_string[len] == '\0')
  1184. {
  1185. gcj::verbose_class_flag = true;
  1186. return 0;
  1187. }
  1188. else
  1189. {
  1190. // unrecognized option beginning with -verbose
  1191. return -1;
  1192. }
  1193. return 0;
  1194. }
  1195. #ifdef INTERPRETER
  1196. // This function loads the agent functions for JVMTI from the library indicated
  1197. // by name. It returns a negative value on failure, the value of which
  1198. // indicates where ltdl failed, it also prints an error message.
  1199. static jint
  1200. load_jvmti_agent (const char *name)
  1201. {
  1202. #ifdef USE_LTDL
  1203. if (lt_dlinit ())
  1204. {
  1205. fprintf (stderr,
  1206. "libgcj: Error in ltdl init while loading agent library.\n");
  1207. return -1;
  1208. }
  1209. lt_dlhandle lib = lt_dlopenext (name);
  1210. if (!lib)
  1211. {
  1212. fprintf (stderr,
  1213. "libgcj: Error opening agent library.\n");
  1214. return -2;
  1215. }
  1216. if (lib)
  1217. {
  1218. jvmti_agentonload
  1219. = (jvmti_agent_onload_func *) lt_dlsym (lib, "Agent_OnLoad");
  1220. if (!jvmti_agentonload)
  1221. {
  1222. fprintf (stderr,
  1223. "libgcj: Error finding agent function in library %s.\n",
  1224. name);
  1225. lt_dlclose (lib);
  1226. lib = NULL;
  1227. return -4;
  1228. }
  1229. else
  1230. {
  1231. jvmti_agentonunload
  1232. = (jvmti_agent_onunload_func *) lt_dlsym (lib, "Agent_OnUnload");
  1233. return 0;
  1234. }
  1235. }
  1236. else
  1237. {
  1238. fprintf (stderr, "libgcj: Library %s not found in library path.\n", name);
  1239. return -3;
  1240. }
  1241. #endif /* USE_LTDL */
  1242. // If LTDL cannot be used, return an error code indicating this.
  1243. return -99;
  1244. }
  1245. #endif // INTERPRETER
  1246. static jint
  1247. parse_init_args (JvVMInitArgs* vm_args)
  1248. {
  1249. // if _Jv_Compiler_Properties is non-NULL then it needs to be
  1250. // re-allocated dynamically.
  1251. if (_Jv_Compiler_Properties)
  1252. {
  1253. const char** props = _Jv_Compiler_Properties;
  1254. _Jv_Compiler_Properties = NULL;
  1255. for (int i = 0; props[i]; i++)
  1256. {
  1257. _Jv_Compiler_Properties = (const char**) _Jv_Realloc
  1258. (_Jv_Compiler_Properties,
  1259. (_Jv_Properties_Count + 1) * sizeof (const char*));
  1260. _Jv_Compiler_Properties[_Jv_Properties_Count++] = props[i];
  1261. }
  1262. }
  1263. if (vm_args == NULL)
  1264. return 0;
  1265. for (int i = 0; i < vm_args->nOptions; ++i)
  1266. {
  1267. char* option_string = vm_args->options[i].optionString;
  1268. if (! strcmp (option_string, "vfprintf")
  1269. || ! strcmp (option_string, "exit")
  1270. || ! strcmp (option_string, "abort"))
  1271. {
  1272. // FIXME: we are required to recognize these, but for
  1273. // now we don't handle them in any way.
  1274. continue;
  1275. }
  1276. else if (! strncmp (option_string,
  1277. "-verbose", sizeof ("-verbose") - 1))
  1278. {
  1279. jint result = parse_verbose_args (option_string,
  1280. vm_args->ignoreUnrecognized);
  1281. if (result < 0)
  1282. return result;
  1283. }
  1284. else if (! strncmp (option_string, "-D", 2))
  1285. {
  1286. _Jv_Compiler_Properties = (const char**) _Jv_Realloc
  1287. (_Jv_Compiler_Properties,
  1288. (_Jv_Properties_Count + 1) * sizeof (char*));
  1289. _Jv_Compiler_Properties[_Jv_Properties_Count++] =
  1290. strdup (option_string + 2);
  1291. continue;
  1292. }
  1293. #ifdef INTERPRETER
  1294. else if (! strncmp (option_string, "-agentlib", sizeof ("-agentlib") - 1))
  1295. {
  1296. char *strPtr;
  1297. if (strlen(option_string) > (sizeof ("-agentlib:") - 1))
  1298. strPtr = &option_string[sizeof ("-agentlib:") - 1];
  1299. else
  1300. {
  1301. fprintf (stderr,
  1302. "libgcj: Malformed agentlib argument %s: expected lib name\n",
  1303. option_string);
  1304. return -1;
  1305. }
  1306. // These are optional arguments to pass to the agent library.
  1307. jvmti_agent_opts = strchr (strPtr, '=');
  1308. if (! strncmp (strPtr, "jdwp", 4))
  1309. {
  1310. // We want to run JDWP here so set the correct variables.
  1311. remoteDebug = true;
  1312. jdwpOptions = ++jvmti_agent_opts;
  1313. }
  1314. else
  1315. {
  1316. jint nameLength;
  1317. if (jvmti_agent_opts == NULL)
  1318. nameLength = strlen (strPtr);
  1319. else
  1320. {
  1321. nameLength = jvmti_agent_opts - strPtr;
  1322. jvmti_agent_opts++;
  1323. }
  1324. char lib_name[nameLength + 3 + 1];
  1325. strcpy (lib_name, "lib");
  1326. strncat (lib_name, strPtr, nameLength);
  1327. jint result = load_jvmti_agent (lib_name);
  1328. if (result < 0)
  1329. {
  1330. return -1;
  1331. }
  1332. // Mark JVMTI active
  1333. JVMTI::enabled = true;
  1334. }
  1335. continue;
  1336. }
  1337. else if (! strncmp (option_string, "-agentpath:",
  1338. sizeof ("-agentpath:") - 1))
  1339. {
  1340. char *strPtr;
  1341. if (strlen(option_string) > 10)
  1342. strPtr = &option_string[10];
  1343. else
  1344. {
  1345. fprintf (stderr,
  1346. "libgcj: Malformed agentlib argument %s: expected lib path\n",
  1347. option_string);
  1348. return -1;
  1349. }
  1350. // These are optional arguments to pass to the agent library.
  1351. jvmti_agent_opts = strchr (strPtr, '=');
  1352. jint nameLength;
  1353. if (jvmti_agent_opts == NULL)
  1354. nameLength = strlen (strPtr);
  1355. else
  1356. {
  1357. nameLength = jvmti_agent_opts - strPtr;
  1358. jvmti_agent_opts++;
  1359. }
  1360. char lib_name[nameLength + 3 + 1];
  1361. strcpy (lib_name, "lib");
  1362. strncat (lib_name, strPtr, nameLength);
  1363. jint result = load_jvmti_agent (strPtr);
  1364. if (result < 0)
  1365. {
  1366. return -1;
  1367. }
  1368. // Mark JVMTI active
  1369. JVMTI::enabled = true;
  1370. continue;
  1371. }
  1372. #endif // INTERPRETER
  1373. else
  1374. {
  1375. int r = -1;
  1376. if (option_string[0] == '_')
  1377. r = parse_x_arg (option_string + 1);
  1378. else if (! strncmp (option_string, "-X", 2))
  1379. r = parse_x_arg (option_string + 2);
  1380. if (r == -1 && ! vm_args->ignoreUnrecognized)
  1381. {
  1382. fprintf (stderr, "libgcj: unknown option: %s\n", option_string);
  1383. return -1;
  1384. }
  1385. }
  1386. }
  1387. return 0;
  1388. }
  1389. jint
  1390. _Jv_CreateJavaVM (JvVMInitArgs* vm_args)
  1391. {
  1392. using namespace gcj;
  1393. if (runtimeInitialized)
  1394. return -1;
  1395. runtimeInitialized = true;
  1396. startTime = _Jv_platform_gettimeofday();
  1397. jint result = parse_init_args (vm_args);
  1398. if (result < 0)
  1399. return -1;
  1400. PROCESS_GCJ_PROPERTIES;
  1401. /* Threads must be initialized before the GC, so that it inherits the
  1402. signal mask. */
  1403. _Jv_InitThreads ();
  1404. _Jv_InitGC ();
  1405. _Jv_InitializeSyncMutex ();
  1406. #ifdef INTERPRETER
  1407. _Jv_InitInterpreter ();
  1408. #endif
  1409. #ifdef HANDLE_SEGV
  1410. INIT_SEGV;
  1411. #endif
  1412. #ifdef HANDLE_FPE
  1413. INIT_FPE;
  1414. #endif
  1415. /* Initialize Utf8 constants declared in jvm.h. */
  1416. void_signature = _Jv_makeUtf8Const ("()V", 3);
  1417. clinit_name = _Jv_makeUtf8Const ("<clinit>", 8);
  1418. init_name = _Jv_makeUtf8Const ("<init>", 6);
  1419. finit_name = _Jv_makeUtf8Const ("finit$", 6);
  1420. /* Initialize built-in classes to represent primitive TYPEs. */
  1421. _Jv_InitPrimClass (&_Jv_byteClass, "byte", 'B', 1);
  1422. _Jv_InitPrimClass (&_Jv_shortClass, "short", 'S', 2);
  1423. _Jv_InitPrimClass (&_Jv_intClass, "int", 'I', 4);
  1424. _Jv_InitPrimClass (&_Jv_longClass, "long", 'J', 8);
  1425. _Jv_InitPrimClass (&_Jv_booleanClass, "boolean", 'Z', 1);
  1426. _Jv_InitPrimClass (&_Jv_charClass, "char", 'C', 2);
  1427. _Jv_InitPrimClass (&_Jv_floatClass, "float", 'F', 4);
  1428. _Jv_InitPrimClass (&_Jv_doubleClass, "double", 'D', 8);
  1429. _Jv_InitPrimClass (&_Jv_voidClass, "void", 'V', 0);
  1430. // We have to initialize this fairly early, to avoid circular class
  1431. // initialization. In particular we want to start the
  1432. // initialization of ClassLoader before we start the initialization
  1433. // of VMClassLoader.
  1434. _Jv_InitClass (&java::lang::ClassLoader::class$);
  1435. // Set up the system class loader and the bootstrap class loader.
  1436. gnu::gcj::runtime::ExtensionClassLoader::initialize();
  1437. java::lang::VMClassLoader::initialize(JvNewStringLatin1(TOOLEXECLIBDIR));
  1438. _Jv_RegisterBootstrapPackages();
  1439. no_memory = new java::lang::OutOfMemoryError;
  1440. #ifdef USE_LTDL
  1441. LTDL_SET_PRELOADED_SYMBOLS ();
  1442. #endif
  1443. _Jv_platform_initialize ();
  1444. _Jv_JNI_Init ();
  1445. #ifdef INTERPRETER
  1446. _Jv_JVMTI_Init ();
  1447. #endif
  1448. _Jv_GCInitializeFinalizers (&::gnu::gcj::runtime::FinalizerThread::finalizerReady);
  1449. // Start the GC finalizer thread. A VirtualMachineError can be
  1450. // thrown by the runtime if, say, threads aren't available.
  1451. try
  1452. {
  1453. using namespace gnu::gcj::runtime;
  1454. FinalizerThread *ft = new FinalizerThread ();
  1455. ft->start ();
  1456. }
  1457. catch (java::lang::VirtualMachineError *ignore)
  1458. {
  1459. }
  1460. runtimeInitialized = true;
  1461. return 0;
  1462. }
  1463. void
  1464. _Jv_RunMain (JvVMInitArgs *vm_args, jclass klass, const char *name, int argc,
  1465. const char **argv, bool is_jar)
  1466. {
  1467. #ifndef DISABLE_MAIN_ARGS
  1468. _Jv_SetArgs (argc, argv);
  1469. #endif
  1470. java::lang::Runtime *runtime = NULL;
  1471. try
  1472. {
  1473. if (_Jv_CreateJavaVM (vm_args) < 0)
  1474. {
  1475. fprintf (stderr, "libgcj: couldn't create virtual machine\n");
  1476. exit (1);
  1477. }
  1478. if (vm_args == NULL)
  1479. gcj::vmArgs = JvConvertArgv(0, NULL);
  1480. else
  1481. {
  1482. const char* vmArgs[vm_args->nOptions];
  1483. const char** vmPtr = vmArgs;
  1484. struct _Jv_VMOption* optionPtr = vm_args->options;
  1485. for (int i = 0; i < vm_args->nOptions; ++i)
  1486. *vmPtr++ = (*optionPtr++).optionString;
  1487. gcj::vmArgs = JvConvertArgv(vm_args->nOptions, vmArgs);
  1488. }
  1489. // Get the Runtime here. We want to initialize it before searching
  1490. // for `main'; that way it will be set up if `main' is a JNI method.
  1491. runtime = java::lang::Runtime::getRuntime ();
  1492. #ifdef DISABLE_MAIN_ARGS
  1493. arg_vec = JvConvertArgv (0, 0);
  1494. #else
  1495. arg_vec = JvConvertArgv (argc - 1, argv + 1);
  1496. #endif
  1497. using namespace gnu::java::lang;
  1498. if (klass)
  1499. main_thread = new MainThread (klass, arg_vec);
  1500. else
  1501. main_thread = new MainThread (JvNewStringUTF (name),
  1502. arg_vec, is_jar);
  1503. _Jv_AttachCurrentThread (main_thread);
  1504. #ifdef INTERPRETER
  1505. // Start JVMTI if an agent function has been found.
  1506. if (jvmti_agentonload)
  1507. (*jvmti_agentonload) (_Jv_GetJavaVM (), jvmti_agent_opts, NULL);
  1508. // Start JDWP
  1509. if (remoteDebug)
  1510. {
  1511. using namespace gnu::classpath::jdwp;
  1512. VMVirtualMachine::initialize ();
  1513. Jdwp *jdwp = new Jdwp ();
  1514. jdwp->setDaemon (true);
  1515. jdwp->configure (JvNewStringLatin1 (jdwpOptions));
  1516. jdwp->start ();
  1517. // Wait for JDWP to initialize and start
  1518. jdwp->join ();
  1519. }
  1520. // Send VMInit
  1521. if (JVMTI_REQUESTED_EVENT (VMInit))
  1522. _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_INIT, main_thread);
  1523. #endif // INTERPRETER
  1524. }
  1525. catch (java::lang::Throwable *t)
  1526. {
  1527. java::lang::System::err->println (JvNewStringLatin1
  1528. ("Exception during runtime initialization"));
  1529. t->printStackTrace();
  1530. if (runtime)
  1531. java::lang::Runtime::exitNoChecksAccessor (1);
  1532. // In case the runtime creation failed.
  1533. ::exit (1);
  1534. }
  1535. _Jv_ThreadRun (main_thread);
  1536. #ifdef INTERPRETER
  1537. // Send VMDeath
  1538. if (JVMTI_REQUESTED_EVENT (VMDeath))
  1539. {
  1540. java::lang::Thread *thread = java::lang::Thread::currentThread ();
  1541. JNIEnv *jni_env = _Jv_GetCurrentJNIEnv ();
  1542. _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_DEATH, thread, jni_env);
  1543. }
  1544. // Run JVMTI AgentOnUnload if it exists and an agent is loaded.
  1545. if (jvmti_agentonunload)
  1546. (*jvmti_agentonunload) (_Jv_GetJavaVM ());
  1547. #endif // INTERPRETER
  1548. // If we got here then something went wrong, as MainThread is not
  1549. // supposed to terminate.
  1550. ::exit (1);
  1551. }
  1552. void
  1553. _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
  1554. bool is_jar)
  1555. {
  1556. _Jv_RunMain (NULL, klass, name, argc, argv, is_jar);
  1557. }
  1558. void
  1559. JvRunMain (jclass klass, int argc, const char **argv)
  1560. {
  1561. _Jv_RunMain (klass, NULL, argc, argv, false);
  1562. }
  1563. void
  1564. JvRunMainName (const char *name, int argc, const char **argv)
  1565. {
  1566. _Jv_RunMain (NULL, name, argc, argv, false);
  1567. }
  1568. // Parse a string and return a heap size.
  1569. static size_t
  1570. parse_memory_size (const char *spec)
  1571. {
  1572. char *end;
  1573. unsigned long val = strtoul (spec, &end, 10);
  1574. if (*end == 'k' || *end == 'K')
  1575. val *= 1024;
  1576. else if (*end == 'm' || *end == 'M')
  1577. val *= 1048576;
  1578. return (size_t) val;
  1579. }
  1580. // Set the initial heap size. This might be ignored by the GC layer.
  1581. // This must be called before _Jv_RunMain.
  1582. void
  1583. _Jv_SetInitialHeapSize (const char *arg)
  1584. {
  1585. size_t size = parse_memory_size (arg);
  1586. _Jv_GCSetInitialHeapSize (size);
  1587. }
  1588. // Set the maximum heap size. This might be ignored by the GC layer.
  1589. // This must be called before _Jv_RunMain.
  1590. void
  1591. _Jv_SetMaximumHeapSize (const char *arg)
  1592. {
  1593. size_t size = parse_memory_size (arg);
  1594. _Jv_GCSetMaximumHeapSize (size);
  1595. }
  1596. void
  1597. _Jv_SetStackSize (const char *arg)
  1598. {
  1599. size_t size = parse_memory_size (arg);
  1600. gcj::stack_size = size;
  1601. }
  1602. void *
  1603. _Jv_Malloc (jsize size)
  1604. {
  1605. if (__builtin_expect (size == 0, false))
  1606. size = 1;
  1607. void *ptr = malloc ((size_t) size);
  1608. if (__builtin_expect (ptr == NULL, false))
  1609. throw no_memory;
  1610. return ptr;
  1611. }
  1612. void *
  1613. _Jv_Realloc (void *ptr, jsize size)
  1614. {
  1615. if (__builtin_expect (size == 0, false))
  1616. size = 1;
  1617. ptr = realloc (ptr, (size_t) size);
  1618. if (__builtin_expect (ptr == NULL, false))
  1619. throw no_memory;
  1620. return ptr;
  1621. }
  1622. void *
  1623. _Jv_MallocUnchecked (jsize size)
  1624. {
  1625. if (__builtin_expect (size == 0, false))
  1626. size = 1;
  1627. return malloc ((size_t) size);
  1628. }
  1629. void
  1630. _Jv_Free (void* ptr)
  1631. {
  1632. return free (ptr);
  1633. }
  1634. // In theory, these routines can be #ifdef'd away on machines which
  1635. // support divide overflow signals. However, we never know if some
  1636. // code might have been compiled with "-fuse-divide-subroutine", so we
  1637. // always include them in libgcj.
  1638. jint
  1639. _Jv_divI (jint dividend, jint divisor)
  1640. {
  1641. if (__builtin_expect (divisor == 0, false))
  1642. {
  1643. java::lang::ArithmeticException *arithexception
  1644. = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
  1645. throw arithexception;
  1646. }
  1647. if (dividend == (jint) 0x80000000L && divisor == -1)
  1648. return dividend;
  1649. return dividend / divisor;
  1650. }
  1651. jint
  1652. _Jv_remI (jint dividend, jint divisor)
  1653. {
  1654. if (__builtin_expect (divisor == 0, false))
  1655. {
  1656. java::lang::ArithmeticException *arithexception
  1657. = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
  1658. throw arithexception;
  1659. }
  1660. if (dividend == (jint) 0x80000000L && divisor == -1)
  1661. return 0;
  1662. return dividend % divisor;
  1663. }
  1664. jlong
  1665. _Jv_divJ (jlong dividend, jlong divisor)
  1666. {
  1667. if (__builtin_expect (divisor == 0, false))
  1668. {
  1669. java::lang::ArithmeticException *arithexception
  1670. = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
  1671. throw arithexception;
  1672. }
  1673. if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
  1674. return dividend;
  1675. return dividend / divisor;
  1676. }
  1677. jlong
  1678. _Jv_remJ (jlong dividend, jlong divisor)
  1679. {
  1680. if (__builtin_expect (divisor == 0, false))
  1681. {
  1682. java::lang::ArithmeticException *arithexception
  1683. = new java::lang::ArithmeticException (JvNewStringLatin1 ("/ by zero"));
  1684. throw arithexception;
  1685. }
  1686. if (dividend == (jlong) 0x8000000000000000LL && divisor == -1)
  1687. return 0;
  1688. return dividend % divisor;
  1689. }
  1690. // Return true if SELF_KLASS can access a field or method in
  1691. // OTHER_KLASS. The field or method's access flags are specified in
  1692. // FLAGS.
  1693. jboolean
  1694. _Jv_CheckAccess (jclass self_klass, jclass other_klass, jint flags)
  1695. {
  1696. using namespace java::lang::reflect;
  1697. return ((self_klass == other_klass)
  1698. || ((flags & Modifier::PUBLIC) != 0)
  1699. || (((flags & Modifier::PROTECTED) != 0)
  1700. && _Jv_IsAssignableFromSlow (self_klass, other_klass))
  1701. || (((flags & Modifier::PRIVATE) == 0)
  1702. && _Jv_ClassNameSamePackage (self_klass->name,
  1703. other_klass->name)));
  1704. }
  1705. // Prepend GCJ_VERSIONED_LIBDIR to a module search path stored in a C
  1706. // char array, if the path is not already prefixed by
  1707. // GCJ_VERSIONED_LIBDIR. Return a newly JvMalloc'd char buffer. The
  1708. // result should be freed using JvFree.
  1709. char*
  1710. _Jv_PrependVersionedLibdir (char* libpath)
  1711. {
  1712. char* retval = 0;
  1713. if (libpath && libpath[0] != '\0')
  1714. {
  1715. if (! strncmp (libpath,
  1716. GCJ_VERSIONED_LIBDIR,
  1717. sizeof (GCJ_VERSIONED_LIBDIR) - 1))
  1718. {
  1719. // LD_LIBRARY_PATH is already prefixed with
  1720. // GCJ_VERSIONED_LIBDIR.
  1721. retval = (char*) _Jv_Malloc (strlen (libpath) + 1);
  1722. strcpy (retval, libpath);
  1723. }
  1724. else
  1725. {
  1726. // LD_LIBRARY_PATH is not prefixed with
  1727. // GCJ_VERSIONED_LIBDIR.
  1728. char path_sep[2];
  1729. path_sep[0] = (char) _Jv_platform_path_separator;
  1730. path_sep[1] = '\0';
  1731. jsize total = ((sizeof (GCJ_VERSIONED_LIBDIR) - 1)
  1732. + 1 /* path separator */ + strlen (libpath) + 1);
  1733. retval = (char*) _Jv_Malloc (total);
  1734. strcpy (retval, GCJ_VERSIONED_LIBDIR);
  1735. strcat (retval, path_sep);
  1736. strcat (retval, libpath);
  1737. }
  1738. }
  1739. else
  1740. {
  1741. // LD_LIBRARY_PATH was not specified or is empty.
  1742. retval = (char*) _Jv_Malloc (sizeof (GCJ_VERSIONED_LIBDIR));
  1743. strcpy (retval, GCJ_VERSIONED_LIBDIR);
  1744. }
  1745. return retval;
  1746. }