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
433433 }
434434 exception e
435435 {
436− "*" =>
436+ "*disabled" =>
437437 #NOTE: a raise is only expected from the init calls therefore
438438 # when we reach here we need to block and acquire
439439 block(t);
440440 acquire();
441441 trace(JVERBOSE, sys->sprint("Some exception: %s", e));
442+ raise e;
442443 if ( str->prefix(JCLDREX+exceptionininitializer, e ) == 1 )
443444 loaderror(exceptionininitializer, e ); #rethrow
444445 else
@@ -476,7 +477,7 @@ loader(name: string): ref Class · 31 unmodified lines
476477 }
477478 exception e
478479 {
479− "*" =>
480+ "*disabled" =>
480481 if(released == 0) {
481482 release();
482483 unblock(t);
@@ -575,6 +576,7 @@ encodename(name: string): string · 92 unmodified lines
575576 #
576577 rtload(addr: int)
577578 {
579+ trace(JVERBOSE, sys->sprint("rtload start"));
578580 o := getabsint(addr + RTTHISOFFSET);
579581 r := getabsint(addr - (o + WORDZ));
580582 l := o + r;
@@ -623,6 +625,7 @@ rtload(addr: int) · 42 unmodified lines
623625 o += WORDZ;
624626 }
625627 cur = nil;
628+ trace(JVERBOSE, sys->sprint("rtload end"));
626629 # if (errors)
627630 # error("rtload failed");
628631 }
@@ -1502,6 +1505,34 @@ interrupt(t: ref ThreadData) · 873 unmodified lines
15021505 }
15031506 }
15041507
1508+#
1509+# Get Class object for the class
1510+#
1511+getclassclass(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+
15051536 #
15061537 # Runtime hierarchy/type check routines.
15071538 #
@@ -1746,24 +1777,25 @@ drem(x, y: real): real · 238 unmodified lines
17461777
17471778 Class.run(c: self ref Class, args: list of string)
17481779 {
1749− m := c.findsmethod(MAINFIELD, MAINSIGNATURE);
1780+ m := c.findsmethod(MAINFIELD, VOIDSIGNATURE);
17501781 if (m == nil)
17511782 loaderror( nosuchmethod, sys->sprint("%s: missing static method main", c.name));
17521783 main = c;
1753− if (arrayclass == nil)
1754− loadarrayclass();
1755− if (stringclass == nil)
1756− loadstringclass();
1757− n := len args;
1758− h := array[n] of ref JavaString;
1759− d := stringclass.moddata;
1760− for (i := 0; i < n; i++) {
1761− h[i] = ref JavaString(d, hd args);
1762− args = tl args;
1763− }
1784+ #if (arrayclass == nil)
1785+ # loadarrayclass();
1786+ #if (stringclass == nil)
1787+ # loadstringclass();
1788+ #n := len args;
1789+ #h := array[n] of ref JavaString;
1790+ #d := stringclass.moddata;
1791+ #for (i := 0; i < n; i++) {
1792+ # h[i] = ref JavaString(d, hd args);
1793+ # args = tl args;
1794+ #}
17641795 #c.xeq(m.value, ref Array(arraymd, h, 1, stringclass, 0));
17651796 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);
17671799 delthreaddata();
17681800 }
17691801
@@ -2291,7 +2323,9 @@ Class.relocate(c: self ref Class) · 521 unmodified lines
22912323 # Install the links.
22922324 #
22932325 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)
22952329 error(sys->sprint("ext failed: %r"));
22962330 }
22972331 #
@@ -2482,12 +2516,6 @@ Class.findvmethod(c: self ref Class, f, s: string): int · 184 unmodified lines
24822516 {
24832517 a := c.virtualmethods;
24842518 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− }
24912519 for (i := 0; i < n; i++) {
24922520 t := a[i].field;
24932521 if (t.field == f && t.signature == s)
@@ -2516,9 +2544,12 @@ Class.loadnative(c: self ref Class) · 22 unmodified lines
25162544 instrs := ld->ifetch(mod);
25172545 if (instrs == nil)
25182546 error(sys->sprint("%s: native ifetch failed: %r",unsatisfiedlink));
2547+ imports := ld->imports(mod);
2548+
25192549 nm := ld->newmod("N-" + c.name, STACKSIZE, len links, instrs, getmd(mod));
25202550 if (nm == nil)
25212551 error(sys->sprint("%s: native newmod failed: %r",unsatisfiedlink));
2552+
25222553 n := len types;
25232554 for (i := 1; i < n; i++) {
25242555 if (ld->tnew(nm, types[i].size, types[i].map) != i)
@@ -2529,6 +2560,8 @@ Class.loadnative(c: self ref Class) · 4 unmodified lines
25292560 if (ld->ext(nm, i, links[i].pc, links[i].tdesc) < 0)
25302561 error(sys->sprint("%s: native ext failed: %r",unsatisfiedlink));
25312562 }
2563+ if (ld->setimports(nm, imports) < 0)
2564+ error(sys->sprint("%s: native setimports failed: %r",unsatisfiedlink));
25322565 addmodclass(nm, c);
25332566 c.native = nm;
25342567 }
@@ -2546,6 +2579,7 @@ Class.getmethod(c: self ref Class, f, s: string, flags: int): int · 11 unmodified lines
25462579 c.loadnative();
25472580 l = c.info.nlinks;
25482581 m = mangle(f, s);
2582+ trace(JDEBUG, sys->sprint("Mangled native name: %s", m));
25492583 } else {
25502584 l = c.info.links;
25512585 m = f + s;
@@ -2996,6 +3030,7 @@ loadkeys := array[] of · 444 unmodified lines
29963030 "rtload",
29973031 "throw",
29983032 "unrescue",
3033+ "getclassclass",
29993034 };
30003035
30013036 #
@@ -3003,6 +3038,9 @@ loadkeys := array[] of · 1 unmodified line
30033038 #
30043039 loadhash(s: string): int
30053040 {
3041+ # TODO: fix
3042+ if (s == "getclassclass")
3043+ return 1;
30063044 return ((s[len s - 1] + 49) * len s + 19 * s[0]) % LDHASH;
30073045 }
30083046
@@ -3249,10 +3287,7 @@ ipatch(inst: array of Loader->Inst, p: array of byte, d: int) · 240 unmodified lines
32493287 x += t >> ISHIFT;
32503288 if (x < 0 || x >= l)
32513289 error("bad inst index");
3252− if (inst[x].op == byte 57 && inst[x].mid == 0) {
3253− trace(JVERBOSE, sys->sprint("Skipping instruction %d", x));
3254− continue;
3255− }
3290+ debugs := sys->sprint("ipatch inst[%d](%d, %d, %d)->", x, inst[x].src, inst[x].mid, inst[x].dst);
32563291 case t & (POP | PTYPE) {
32573292 PSRC | PIMM or PSRC | PSIND =>
32583293 inst[x].src += d;
@@ -3275,6 +3310,7 @@ ipatch(inst: array of Loader->Inst, p: array of byte, d: int) · 16 unmodified lines
32753310 * =>
32763311 error("bad reloc");
32773312 }
3313+ #trace(JDEBUG, sys->sprint("%sinst[%d](%d, %d, %d)", debugs, x, inst[x].src, inst[x].mid, inst[x].dst));
32783314 }
32793315 } else {
32803316 for (i := 0; i < n; i++) {
@@ -3439,7 +3475,7 @@ runmain( classloader : JavaClassLoader, classname : string, argv : list of strin · 158 unmodified lines
34393475 }
34403476 exception e
34413477 {
3442− "*" =>
3478+ "*disabled" =>
34433479 m := sys->sprint("uncaught exception: %s", e);
34443480 mesg(m);
34453481 if ( (obj := culprit(e)) != nil)