History

Implemented ldc class loading, runtime part.

Also some changes in debug behavior, I'm sorry for any garbage that I left here, I will clean it up some day. Disabled exceptions (for better debugging) and fixed native class loading.

Dmitry Kabak (userdima committed 13 years ago

Commit 56c0af11 parent 520ef8d2 files · +64 −27Browse files

Showing the changes to java/appl/java/classloader.b (1 of 2 files). Show all

Unified · Split

java/appl/java/classloader.b+63−27
@@ -433,12 +433,13 @@ doreloc() · 432 unmodified lines
433 }433 }
434 exception e434 exception e
435 {435 {
436 "*" =>436 "*disabled" =>
437 #NOTE: a raise is only expected from the init calls therefore437 #NOTE: a raise is only expected from the init calls therefore
438 # when we reach here we need to block and acquire438 # when we reach here we need to block and acquire
439 block(t);439 block(t);
440 acquire();440 acquire();
441 trace(JVERBOSE, sys->sprint("Some exception: %s", e));441 trace(JVERBOSE, sys->sprint("Some exception: %s", e));
442 raise e;
442 if ( str->prefix(JCLDREX+exceptionininitializer, e ) == 1 )443 if ( str->prefix(JCLDREX+exceptionininitializer, e ) == 1 )
443 loaderror(exceptionininitializer, e ); #rethrow444 loaderror(exceptionininitializer, e ); #rethrow
444 else 445 else
@@ -476,7 +477,7 @@ loader(name: string): ref Class · 31 unmodified lines
476 }477 }
477 exception e478 exception e
478 {479 {
479 "*" =>480 "*disabled" =>
480 if(released == 0) {481 if(released == 0) {
481 release();482 release();
482 unblock(t);483 unblock(t);
@@ -575,6 +576,7 @@ encodename(name: string): string · 92 unmodified lines
575#576#
576rtload(addr: int)577rtload(addr: int)
577{578{
579 trace(JVERBOSE, sys->sprint("rtload start"));
578 o := getabsint(addr + RTTHISOFFSET);580 o := getabsint(addr + RTTHISOFFSET);
579 r := getabsint(addr - (o + WORDZ));581 r := getabsint(addr - (o + WORDZ));
580 l := o + r;582 l := o + r;
@@ -623,6 +625,7 @@ rtload(addr: int) · 42 unmodified lines
623 o += WORDZ;625 o += WORDZ;
624 }626 }
625 cur = nil;627 cur = nil;
628 trace(JVERBOSE, sys->sprint("rtload end"));
626# if (errors)629# if (errors)
627# error("rtload failed");630# error("rtload failed");
628}631}
@@ -1502,6 +1505,34 @@ interrupt(t: ref ThreadData) · 873 unmodified lines
1502 }1505 }
1503}1506}
1504 1507
1508#
1509# Get Class object for the class
1510#
1511getclassclass(caller: string, class: string): ref Object
1512{
1513 c := getclass(caller);
1514 if (c == nil)
1515 sthrow("NullPointerException");
1516
1517 trace(JDEBUG, sys->sprint("Getclassclass called, %s asked for class %s", c.name, class));
1518
1519 # TODO: put those strings in header
1520 # Prepare necessary classes
1521 if (stringclass == nil)
1522 loadstringclass();
1523 cc := getclass("java/lang/Class");
1524 if (cc == nil)
1525 sthrow("NullPointerException");
1526 f := cc.findsmethod("forName", "(Ljava/lang/String;)Ljava/lang/Class;");
1527 if (f == nil)
1528 error(sys->sprint("%s: %s: missing forName0 in Class", nosuchmethod, cc.name));
1529 result := cc.call(f.value, JStoObject(ref JavaString(stringclass.moddata, class)));
1530
1531 trace(JDEBUG, sys->sprint("forName0 returned something, i think, %d", result != nil));
1532
1533 return result;
1534}
1535
1505#1536#
1506# Runtime hierarchy/type check routines.1537# Runtime hierarchy/type check routines.
1507#1538#
@@ -1746,24 +1777,25 @@ drem(x, y: real): real · 238 unmodified lines
1746 1777
1747Class.run(c: self ref Class, args: list of string)1778Class.run(c: self ref Class, args: list of string)
1748{1779{
1749 m := c.findsmethod(MAINFIELD, MAINSIGNATURE);1780 m := c.findsmethod(MAINFIELD, VOIDSIGNATURE);
1750 if (m == nil)1781 if (m == nil)
1751 loaderror( nosuchmethod, sys->sprint("%s: missing static method main", c.name));1782 loaderror( nosuchmethod, sys->sprint("%s: missing static method main", c.name));
1752 main = c;1783 main = c;
1753 if (arrayclass == nil)1784 #if (arrayclass == nil)
1754 loadarrayclass();1785 # loadarrayclass();
1755 if (stringclass == nil)1786 #if (stringclass == nil)
1756 loadstringclass();1787 # loadstringclass();
1757 n := len args;1788 #n := len args;
1758 h := array[n] of ref JavaString;1789 #h := array[n] of ref JavaString;
1759 d := stringclass.moddata;1790 #d := stringclass.moddata;
1760 for (i := 0; i < n; i++) {1791 #for (i := 0; i < n; i++) {
1761 h[i] = ref JavaString(d, hd args);1792 # h[i] = ref JavaString(d, hd args);
1762 args = tl args;1793 # args = tl args;
1763 }1794 #}
1764 #c.xeq(m.value, ref Array(arraymd, h, 1, stringclass, 0));1795 #c.xeq(m.value, ref Array(arraymd, h, 1, stringclass, 0));
1765 getthreaddata();1796 getthreaddata();
1766 r := jassist->mcalla(c.mod, m.value, ref Array(arraymd, h, 1, stringclass, 0));1797 #r := jassist->mcalla(c.mod, m.value, ref Array(arraymd, h, 1, stringclass, 0));
1798 r := jassist->mcall0(c.mod, m.value);
1767 delthreaddata();1799 delthreaddata();
1768}1800}
1769 1801
@@ -2291,7 +2323,9 @@ Class.relocate(c: self ref Class) · 521 unmodified lines
2291 # Install the links.2323 # Install the links.
2292 #2324 #
2293 for (i = 0; i < len links; i++) {2325 for (i = 0; i < len links; i++) {
2294 if (ld->ext(c.mod, i, links[i].pc, links[i].tdesc) < 0)2326 trace(JDEBUG, sys->sprint("link %d pc %d tdesc %d name %s",
2327 i, links[i].pc, links[i].tdesc, links[i].name));
2328 if (ld->ext(c.mod, i, links[i].pc, links[i].tdesc) < 0)
2295 error(sys->sprint("ext failed: %r"));2329 error(sys->sprint("ext failed: %r"));
2296 }2330 }
2297 #2331 #
@@ -2482,12 +2516,6 @@ Class.findvmethod(c: self ref Class, f, s: string): int · 184 unmodified lines
2482{2516{
2483 a := c.virtualmethods;2517 a := c.virtualmethods;
2484 n := len a;2518 n := len a;
2485 if (c.name == "java/lang/StringBuffer") {
2486 trace(JDEBUG, sys->sprint("Class: %s, virtual methods: %d", c.name, n));
2487 trace(JDEBUG, sys->sprint("Started looking for method: %s, %s", f, s));
2488 statenames := array [] of {"NEW", "HIER", "RESOLVE", "LOADED", "INITED"};
2489 trace(JDEBUG, sys->sprint("Class state: %s", statenames[c.state]));
2490 }
2491 for (i := 0; i < n; i++) {2519 for (i := 0; i < n; i++) {
2492 t := a[i].field;2520 t := a[i].field;
2493 if (t.field == f && t.signature == s)2521 if (t.field == f && t.signature == s)
@@ -2516,9 +2544,12 @@ Class.loadnative(c: self ref Class) · 22 unmodified lines
2516 instrs := ld->ifetch(mod);2544 instrs := ld->ifetch(mod);
2517 if (instrs == nil)2545 if (instrs == nil)
2518 error(sys->sprint("%s: native ifetch failed: %r",unsatisfiedlink));2546 error(sys->sprint("%s: native ifetch failed: %r",unsatisfiedlink));
2547 imports := ld->imports(mod);
2548
2519 nm := ld->newmod("N-" + c.name, STACKSIZE, len links, instrs, getmd(mod));2549 nm := ld->newmod("N-" + c.name, STACKSIZE, len links, instrs, getmd(mod));
2520 if (nm == nil)2550 if (nm == nil)
2521 error(sys->sprint("%s: native newmod failed: %r",unsatisfiedlink));2551 error(sys->sprint("%s: native newmod failed: %r",unsatisfiedlink));
2552
2522 n := len types;2553 n := len types;
2523 for (i := 1; i < n; i++) {2554 for (i := 1; i < n; i++) {
2524 if (ld->tnew(nm, types[i].size, types[i].map) != i)2555 if (ld->tnew(nm, types[i].size, types[i].map) != i)
@@ -2529,6 +2560,8 @@ Class.loadnative(c: self ref Class) · 4 unmodified lines
2529 if (ld->ext(nm, i, links[i].pc, links[i].tdesc) < 0)2560 if (ld->ext(nm, i, links[i].pc, links[i].tdesc) < 0)
2530 error(sys->sprint("%s: native ext failed: %r",unsatisfiedlink));2561 error(sys->sprint("%s: native ext failed: %r",unsatisfiedlink));
2531 }2562 }
2563 if (ld->setimports(nm, imports) < 0)
2564 error(sys->sprint("%s: native setimports failed: %r",unsatisfiedlink));
2532 addmodclass(nm, c);2565 addmodclass(nm, c);
2533 c.native = nm;2566 c.native = nm;
2534}2567}
@@ -2546,6 +2579,7 @@ Class.getmethod(c: self ref Class, f, s: string, flags: int): int · 11 unmodified lines
2546 c.loadnative();2579 c.loadnative();
2547 l = c.info.nlinks;2580 l = c.info.nlinks;
2548 m = mangle(f, s);2581 m = mangle(f, s);
2582 trace(JDEBUG, sys->sprint("Mangled native name: %s", m));
2549 } else {2583 } else {
2550 l = c.info.links;2584 l = c.info.links;
2551 m = f + s;2585 m = f + s;
@@ -2996,6 +3030,7 @@ loadkeys := array[] of · 444 unmodified lines
2996 "rtload",3030 "rtload",
2997 "throw",3031 "throw",
2998 "unrescue",3032 "unrescue",
3033 "getclassclass",
2999};3034};
3000 3035
3001#3036#
@@ -3003,6 +3038,9 @@ loadkeys := array[] of · 1 unmodified line
3003#3038#
3004loadhash(s: string): int3039loadhash(s: string): int
3005{3040{
3041 # TODO: fix
3042 if (s == "getclassclass")
3043 return 1;
3006 return ((s[len s - 1] + 49) * len s + 19 * s[0]) % LDHASH;3044 return ((s[len s - 1] + 49) * len s + 19 * s[0]) % LDHASH;
3007}3045}
3008 3046
@@ -3249,10 +3287,7 @@ ipatch(inst: array of Loader->Inst, p: array of byte, d: int) · 240 unmodified lines
3249 x += t >> ISHIFT;3287 x += t >> ISHIFT;
3250 if (x < 0 || x >= l)3288 if (x < 0 || x >= l)
3251 error("bad inst index");3289 error("bad inst index");
3252 if (inst[x].op == byte 57 && inst[x].mid == 0) {3290 debugs := sys->sprint("ipatch inst[%d](%d, %d, %d)->", x, inst[x].src, inst[x].mid, inst[x].dst);
3253 trace(JVERBOSE, sys->sprint("Skipping instruction %d", x));
3254 continue;
3255 }
3256 case t & (POP | PTYPE) {3291 case t & (POP | PTYPE) {
3257 PSRC | PIMM or PSRC | PSIND =>3292 PSRC | PIMM or PSRC | PSIND =>
3258 inst[x].src += d;3293 inst[x].src += d;
@@ -3275,6 +3310,7 @@ ipatch(inst: array of Loader->Inst, p: array of byte, d: int) · 16 unmodified lines
3275 * =>3310 * =>
3276 error("bad reloc");3311 error("bad reloc");
3277 }3312 }
3313 #trace(JDEBUG, sys->sprint("%sinst[%d](%d, %d, %d)", debugs, x, inst[x].src, inst[x].mid, inst[x].dst));
3278 }3314 }
3279 } else {3315 } else {
3280 for (i := 0; i < n; i++) {3316 for (i := 0; i < n; i++) {
@@ -3439,7 +3475,7 @@ runmain( classloader : JavaClassLoader, classname : string, argv : list of strin · 158 unmodified lines
3439 }3475 }
3440 exception e3476 exception e
3441 {3477 {
3442 "*" =>3478 "*disabled" =>
3443 m := sys->sprint("uncaught exception: %s", e);3479 m := sys->sprint("uncaught exception: %s", e);
3444 mesg(m);3480 mesg(m);
3445 if ( (obj := culprit(e)) != nil) 3481 if ( (obj := culprit(e)) != nil)